How to get 'event' as argument from javascript 'onclick' function?

Use the 'event' object in the the 'onclick' function

e.g
<button onclick="myFunction(event,this)">Click me</button>
    <script>
        function myFunction(e, element) {
            console.log("event=", e, "element=", element);
        }
    </script>
output:









Sample code and demo is here

Demo

No comments:

Post a Comment