JQuery functionality without jQuery

I was wondering how to achieve jQuery.live functionality using "traditional" JavaScript. I want something like $ ('a'). Live ('mouseover', mouseover_func) will be written like normal JavaScript. But how?

+6
javascript jquery
source share
2 answers

Bind the mouseover event handler to the <body> element. In this handler, check the "target" property of each event that it catches, and see if its "tagName" "A" property. If so, call the handler.

The live function uses the bubbling event, which is the name of the browser process to check handlers from the target element to the DOM root, one parent at a time. Since each <a> in your document can ultimately be traced back to <body> , this root node will receive all mouse events that will not be disabled by lower-level handlers that cancel bubbling (via the stopPropagation () method on the event object or some weird way specific to the browser, I suppose).

However, not all event bubbles. I'm looking for a good link ... here, the MDC page seems pretty good , although maybe a little old.

+10
source share

Just read the jQuery source code to find out how it does it. This is one of the joys of open source. You will learn a lot ...

0
source share

All Articles