Omar
Omar

Reputation: 8145

jquery label not chaging on button click

I'm having a problem where a label is not changing on button click. here is the html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

    <script src="JavaScript.js"></script>
</head>
<body>
    <button id="b">aa</button>
    <label id="sum">0</label>
</body>
</html>

js:

$(document).ready(function () {
    var sum = 1;

    $("#b").on('click', function (event) {
        $("#sum").text = "aa";
    });
});

Why?

Upvotes: 0

Views: 51

Answers (4)

Manish Chauhan
Manish Chauhan

Reputation: 570

You can not assign value using = in jQuery.

This is wrong in your code $("#sum").text = "aa";

Instead this you have to use $("#sum").text("aa"); which is right way to assign value using jQuery.

Upvotes: 0

Romaindr
Romaindr

Reputation: 311

$(document).ready(function () {
    var sum = 1;

    $("#b").on('click', function (event) {
        $("#sum").text("aa");
    });
});

Upvotes: 0

ksalk
ksalk

Reputation: 503

Try this:

$(document).ready(function () {
    var sum = 1;

    $("#b").on('click', function (event) {
        $("#sum").text("aa");
    });
});

Upvotes: 0

Roland Mai
Roland Mai

Reputation: 31077

Your code should be:

$("#sum").text("aa"); 

Upvotes: 2

Related Questions