Try this:
$('body').on('click','[productId]',function(event) {
// do something
});
Demo: http://jsfiddle.net/L5jg8/
This uses the delegated form of the .on()
method. When a click on the body occurs, jQuery will check if it was on an element that matches the selector in the second parameter. (If you're using an old version of jQuery you'll need to use .delegate()
instead of .on()
. If you're using a ludicrously old version try .live()
.)
Your existing code didn't work because event.target
gives you the DOM element that initiated the event, i.e., the lowest-level child that you clicked on (which as you've found could be one of the children of the div you're trying to test for).