Toggle button text on click jquery

I'm looking for toggle button text on click using jquery, but it doesn't work as expected.

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

      

On the 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?

+3


source to share


2 answers


I have highlighted your problem and you can try using it.

Demo JSFiddle



Try using instead val()

.

$("#btnedit").click(function (e) {    
    $(this).val("Edit" ? "Cancel" : "Edit");
});

      

+1


source


Your selector does not look correct to me

 $("#<%= btnedit.ClientID %>")

      



it should be

 $("#btnedit")

      

0


source







All Articles