Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  188] [ 5]  / answers: 1 / hits: 13683  / 10 Years ago, tue, february 25, 2014, 12:00:00

Let's say I got a simple click event for a HTML div.
If I click on the div it should trigger a fadeToggle.



In that div I got another div with another trigger.
On that click event it should do something but instead of doing the event it triggers the first event.



How do I prevent event 1 from triggering if I want event2 to trigger?



Event1 should trigger only if I don't press the clickevent on the second event everything else should trigger as usual.



Thanks for your time



HTML



<div id=1>
Event 1
<div id=2>
<div id=3>
but here is something as well event2
</div>
</div>
</div>


JavaScript



$(#1).click(function() {
$(this).slideToggle();
});


$(#3).click(function() {
$(this).css(background-color, blue);
});


Fiddle: http://jsfiddle.net/VLcxJ/


More From » jquery

 Answers
8
$(#3).click(function(e) {
e.stopPropagation();
$(this).css(background-color, blue);
});


After that, clicks on #3 won't reach #2 or #1


[#47426] Monday, February 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cadendericki

Total Points: 482
Total Questions: 109
Total Answers: 103

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;