AKS
AKS

Reputation: 113

Can't change text in .click jquery

I have paragraph in html and want to change it's text by click on a button. Text changes sometimes for a second but returns to previous state. I can't understand why.

   $(document).ready(function () {
         $("#login_error").text('first');
         $("#authorization_button").click(function () {
         $("#login_error").text('second');
       });
});


<p id="login_error"></p>

So, $("#login_error").text('first'); works, but $("#login_error").text('second'); doesn't.

Upvotes: 0

Views: 330

Answers (1)

DataVader
DataVader

Reputation: 28

I believe you need a event.preventDefault(); under your button so it would look like this

$(document).ready(function () {
            $("#login_error").text('first');
            $("#authorization_button").click(function () {
event.preventDefault();
                $("#login_error").text('second');
            });

maybe..

Upvotes: 1

Related Questions