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

Comments

Popular posts from this blog

Gove confirms mandatory housebuilding targets for councils will be abolished in face of Tory rebellion – UK politics live

Kotak Mahindra Bank Recruitment 2022 Released for Graduate Candidates And Apply Online