Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  133] [ 4]  / answers: 1 / hits: 29197  / 15 Years ago, wed, june 10, 2009, 12:00:00

I've got a JavaScript-function that sets the onclick-event of some HTML-Nodes - even if that onclick-event has been set before.



How can i check if that event has already been set, so I can extend my function to set the event only on HTML-Nodes where it has not already been set?


More From » events

 Answers
128

Check, like this:



if(typeof someNode.onclick == function) {
// someNode has an event handler already set for the onclick event...
}


By the way, if you are using a library, you should say so - if you are, it might be easier/cleaner and would differ based on which library you are using...


[#99344] Friday, June 5, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
suzanne

Total Points: 425
Total Questions: 87
Total Answers: 109

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
;