Javascript Event Priority

With various ways to add events to javascript, do any of them take precedence, like css classes? For example, the built-in onclick even always starts before adding addEventListener?

If not, is there a way to prioritize the event?

+4
source share
2 answers

Yes

The inline handler onclickwill bind when the DOM loads

While everything that you add with .onor .addEventListenerwill have to wait for the DOM element to load.

See here: http://jsfiddle.net/DmxNU/

Your html

<a href="#" onclick="console.log('hello');">click</a>

Your js (jQuery in this case)

$(function() {
    $("a").click(console.log.bind(console, "world"));
});

Exit

hello
world

Explanation

, , . DOM API , , . onclick, .

+4

JavaScript . , .

, , onclick attribut , true, , .

@Kevin B

+2

All Articles