jquery - Click function, inside .off removed handler, want it back -
need help.
i want to:
- click on div makes .active
- click on span inside div removes .active div
there's demo of way tried this:
$('div').on( 'click', function() { if (!$(this).hasclass('active')) $(this).addclass('active'); // span pressed $('div.active span').click( function() { $('div.active').off(); // removing div handler $('div.active').removeclass('active'); }); }); problem: once i've clicked div , span in it, i cannot click jquery action further times, once in element
am doing wrong handlers? please tell me how this.
try this
$( function() { $('div').click(function() { if (!$(this).hasclass('active')) $(this).addclass('active'); }); // x pressed $('body').on('click','div.active span', function() { $(this).parent().removeclass('active'); }); });
Comments
Post a Comment