Functions and access | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Functions and access

I have two questions: 1.How can i access an element that has a particular function name in javascript? 2.How can i know if a particular event attribute has been triggered a specific number of times in JavaScript?

29th Jul 2020, 5:09 PM
Goke Ekundayo
Goke Ekundayo - avatar
7 Answers
+ 1
For number of events just define a var a = 0 ; Define a function on that event such that onevent a++; console.log (a) ;
29th Jul 2020, 6:28 PM
Divya Mohan
Divya Mohan - avatar
+ 3
Ok i get it thank you
29th Jul 2020, 6:48 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 3
For q1: I mean how can i know if an element has an event attribute For example: <button onclick="show()" id="b" >: How can i know if the button has a particular function name as its event attribute
29th Jul 2020, 6:50 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 2
You didnt get me: I mean how can i know the number of times an event has been triggered
29th Jul 2020, 6:47 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 2
Ok thank you
29th Jul 2020, 8:16 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 1
Will you clear q1 more plz.
29th Jul 2020, 6:29 PM
Divya Mohan
Divya Mohan - avatar
+ 1
Var btn = document.getElementById("btn") ; console.log(btn.getAttribute("onclick")) ; It will return the value of attribute value i.e. function name
29th Jul 2020, 7:20 PM
Divya Mohan
Divya Mohan - avatar