React to classes added via Jquery -
i have menu on website displayed , hidden when users click on link.
normally, use toggle this. however, have other menus on page , need close them when displayed (i applying/removing animations classes). think best way of doing adding class of close
link , reacting added class (as other menus have close
class).
however, jquery doesn't seem react classes added via jquery. have searched around , found can use live() purpose. but, live() depreciated , supposed use on() instead.
the way use on follows:
$('.anchor').on('click', '.close', function()
but doesn't seem work. i've tried variations of this, none of them seem work.
how can jquery react classes has added.
bind click events document , remove class .close
on .anchor
click , vice versa.
$(document).on('click','.anchor', function() { $(this).removeclass('anchor'); $(this).addclass('close'); // ...
and
$(document).on('click', '.close', function() { $(this).removeclass('close'); $(this).addclass('anchor'); // ...
note: better wrap html in div , bind events div instead of binding whole document.
update
or better change class on close link .anchor
, use code.
$(document).on('click','.anchor', function() { $('.anchor').addclass('close'); $('.anchor').removeclass('anchor'); // ...
and
$(document).on('click','.close', function() { $('.close').addclass('anchor'); $('.close').removeclass('close'); // ...
Comments
Post a Comment