javascript onclick get event

Solutions on MaxInterview for javascript onclick get event by the best coders in the world

showing results for - "javascript onclick get event"
Daniel
29 May 2020
1<div onclick="doSomething(event,this)"></div>
2<script>
3     function doSomething(e,el){
4         e = e || window.event;
5         console.log(e); //will be the event
6         console.log(el); //we be the dom element 
7     }
8</script>
Mohamed
13 Sep 2020
1var ele = document.getElementById('x');
2if(typeof ele.click == 'function') {
3  ele.click()
4} else if(typeof ele.onclick == 'function') {
5  ele.onclick()
6}
similar questions
queries leading to this page
javascript onclick get event