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.

jsfiddle here

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.

http://jsfiddle.net/mq5xx/

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');   // ... 

http://jsfiddle.net/mq5xx/1/


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 -