jquery - AddClass/RemoveClass Issues -


on click of button class a, replace class class b. on click of button class b need perform action.

it's applying/removing class correctly reason won't select class b?

$(".changebut").click(function () {    $("input[type=text]").fadeout("fast", function () {        $(".changebut").animate({            width: "100%"        }, 200).val("submit again").removeclass("changebut").addclass("submitbut")     }) }), $(".submitbut").click(function () {     alert('it worked!') }) 

fiddle

the easiest solution if use event delegation instead of direct binding :

$(document).on('click', '.changebut', function () {     $("input[type=text]").fadeout("fast", function () {         $(".changebut").animate({              width: "100%"          }, 200).val("submit again").removeclass("changebut").addclass("submitbut")     }); })  $(document).on('click', '.submitbut', function () {     alert('it worked!') }) 

the best solution bind click event directly , check current class :

$(".changebut").on('click', function () {     if($(this).is('.changebut')){         $("input[type=text]").fadeout("fast", function () {             $(".changebut").animate({                 width: "100%"             }, 200).val("submit again").removeclass("changebut").addclass("submitbut")         });     }else{         alert('i have other class');     } }) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -