Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle text of a button on click Jquery

I'm looking to toggle the text of a button on the click using jquery, But it is not working properly.

<asp:Button ID="btnedit" runat="server" Text="Edit" Visible="True"
                    CssClass="actButton" CausesValidation="False" OnClick="btnedit_Click" />

On client-side:

$("#<%= btnedit.ClientID %>").click(function (e) {    
    $(this).text(function (i, text) {
        return text === "Edit" ? "Cancel" : "Edit";
    });
});

Can someone please advise me how to solve this?


1 Answers

I isolated your problem and you could try using this.

JSFiddle demo

Try using val() instead.

$("#btnedit").click(function (e) {    
    $(this).val("Edit" ? "Cancel" : "Edit");
});
like image 81
Rey Libutan Avatar answered Nov 19 '25 08:11

Rey Libutan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!