The correct design of the calling of javascript functions


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
How to execute function call (js) when clicking on the link, button or any other element. A long time ago I was taught to write the call in the onclick(), but I've seen a few other variants of this action.

So I want to know how did the most right to do it?
by | 5 views

5 Answers

0 like 0 dislike
Right — when it runs, if you are interested in the technique of Unobtrusive Javascript, I advise you to brush up the DOM, starting from the second level, there is a description of the event. It has its fineness and a non-standard implementation in Microsoft Internet Explorer. But I repeat: the true test and right when it all works, and how you did it no one is interested!
by
0 like 0 dislike
document.getElementById('elementId').onclick = function(event) { event = event || window.event; ... } 
by
0 like 0 dislike
1. Hang up event to the selector
2. onclick
3. For links like this: href="javascript:funcName()"
by
0 like 0 dislike
to more accurately describe the elements selectors and hang handlers
by
0 like 0 dislike
You can look at the JQuery library as there is implemented a function call to events like click, change, etc.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked May 23, 2019 by Gokilla
0 like 0 dislike
2 answers
asked Apr 26, 2019 by DollyPapper
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
27,849 users