javascript - jQuery function prevents add / remove class on click -


i'm trying have div new class (which makes expand) when being clicked, , old class (which makes close) when clicking on cancel link inside div.

<div class="new-discussion small">     <a class="cancel">cancel</a> </div>  <script>     $('.new-discussion.small').click(function() {         $(this).addclass("expand").removeclass("small");     });     $('a.cancel').click(function() {         $('.new-discussion.expand').addclass("small").removeclass("expand");     }); </script> 

now, adding expand class works flawlessly, closing panel after clicking on cancel link works when remove code:

$('.new-discussion.small').click(function() {     $(this).addclass("expand").removeclass("small"); }); 

so guess must preventing second function work, can't figure out why.

any ideas? thanks!

try this

$('a.cancel').click(function() {     $('.new-discussion.expand').addclass("small").removeclass("expand");     return false; }); 

reason may click event getting propagated parent listening click event.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -