javascript - Replacing image and class with jquery -


i'm using code replace image , add/remove classes jquery when clicked. when click first time works fine, when click second time same thing first jquery click command though click commands called based on classes added , removed. in example find cursor turns pointer click, towards bottom middle, when click button move above cursor, when click fadeout , in same image appear.

please help

demo

//on arrow click //fade page out //replace open nav  $('.arrow_up').bind('click',function() {     $('.bg').fadeout(500);     settimeout(function(){     $('.bg').attr('src', 'other_files/images/bg_open_nav.png');     }, 500);     $('.bg').fadein(500);     $('.arrow').removeclass('arrow_up').addclass('arrow_down'); });  //on arrow down click //fade page out //replace closed nav  $('.arrow_down').bind('click',function() {     $('.bg').fadeout(500);     settimeout(function(){     $('.bg').attr('src', 'other_files/images/bg.png');     }, 500);     $('.bg').fadein(500);     $('.arrow').removeclass('arrow_down').addclass('arrow_up'); }); 

i think js has compiled moment dom has loaded. such, $('.arrow_up') defined , $('.arrow_down') isn't. button element has been initialized $('.arrow_up') , events bound executing.

why don't create separate button arrow_down , use css handle whether displayed or not. should solve problem


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -