Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when i click the button all button text are changed.what i do?

What I have tried:



$(document).ready(function(){

$(".showhide").click(function(){
$(this).parent().find(".content").toggle("slow", function(){
if ($(this).is(":visible")) {
$(".showhide").text("hide");
}
else{
$(".showhide").text("show");
}


});
});
});
Posted
Updated 2-Nov-18 4:07am

1 solution

Store the clicked button in the outer event handler, and use that to update the text:
JavaScript
$(document).ready(function(){
    $(".showhide").click(function(){
        var btn = $(this); // <-- The button which was clicked
        btn.parent().find(".content").toggle("slow", function(){
            if ($(this).is(":visible")) {
                btn.text("hide");
            }
            else {
                btn.text("show");
            }
        });
    });
}); 
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900