Dan G. Switzer, II wrote:
$(document).bind("click", function (e){
        // get the target element (srcElement for IE, originalTarget for
W3C)
        var el = e.srcElement || e.originalTarget;
        if( el.tagName == "A" && el.className == "icon" ){
                alert("Hey, I'm an a.icon element!!!");
                return false;
        }
});

A couple of more notes on this.

1) Instead of attaching the event to the document, you could attach it to
the a specific parent element (i.e. $("ol.icons") instead of $(document).)
This would obviously save some processing.

2) The other benefit of this method, is that you won't need to "reattach"
the behavior if you replace the inner contents of "ol.icons". This means you
can repopulate the images with a different subset loaded dynamically,
without having to re-parse the elements on each dynamic load.
Another note: Using event.target should be good enough, as jQuery normalizes target in IE (srcElement) and Safari (fix textnodes).

--
Jörn Zaefferer

http://bassistance.de

Reply via email to