Answer the question
In order to leave comments, you need to log in
Proper javascript function call formatting
How to properly format a function call (js) when clicking on a link, button or any other element. I was taught a long time ago to write a call to onclick(), but I have seen several other variations of this action.
Therefore, I want to know how to do it most correctly?
Answer the question
In order to leave comments, you need to log in
That's right - this is when it works, if you are interested in the Unobtrusive Javascript technique , then I advise you to learn DOM , starting from the second level, events are described there. There are subtleties and gems, such as non-standard implementation in Microsoft Internet Explorer. But I repeat once again: right and true is when everything works, and how you did it is of no interest to anyone!
document.getElementById('elementId').onclick = function(event) {
event = event || window.event;
...
}
1. Hang an event on the selector
2. onclick
3. For links, you can do this: href="javascript:funcName()"
most correctly describe elements with selectors and hang handlers
You can peep in the JQuery library how functions are called on events like click, change, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question