Hi guys , I am stuck with a little problem with JQuery , I want to apply an OnClick event to a parent div and all of its childs except one child, the child has its own Onclick event . What happens is that when I click on that specific child , it executes its OnClick event and then executes the parent's event. The problem here is that I want the specific child to execute its event only without executing the parent event ... that's my code : $("#parent").click(function() { // executes the parent's event ...... // This applies to all childs ...... }); $("#specific-child").click(function() { // executes the child's event ...... }); HTML: And this is the HTML structure : <div id="parent"> <div> text ....</div> <div> text ....</div> <div> text ....</div> <div> text ....</div> <div id="specific-child"> specific content over here ...</div> </div> HTML:
Hmm... I think the easiest way would be to do something like this: $("#parent").click(function(e){ e = e || window.event; if ((e.srcElement || e.target).id == 'specific-child') return; //leave the function ... PHP:
thanks so much for your help , but actually it doesn't work . I could figure out something like : if ($(e.target).attr('id') == 'specific-child') return; PHP: that's working for Jquery using the factory function ($)and it worked perfectly . thanks one more time .
Strange, I tried it. Glad you got it to work though. You might want to post on the sitepoint forum that you got it solved.