I
I
ilya_compman2010-09-07 03:53:10
JavaScript
ilya_compman, 2010-09-07 03:53:10

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

5 answer(s)
N
npFly, 2010-09-07
@ilya_compman

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!

B
Borro, 2010-09-07
@Borro


document.getElementById('elementId').onclick = function(event) {
    event = event || window.event;
   ...
}

@
@SSoft, 2010-09-07
_

1. Hang an event on the selector
2. onclick
3. For links, you can do this: href="javascript:funcName()"

S
striker_vlad, 2010-09-07
@striker_vlad

most correctly describe elements with selectors and hang handlers

I
Ivan GiBSON, 2010-09-07
@gibson_dev

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 question

Ask a Question

731 491 924 answers to any question