Reputation: 8145
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
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
Reputation: 311
$(document).ready(function () {
var sum = 1;
$("#b").on('click', function (event) {
$("#sum").text("aa");
});
});
Upvotes: 0
Reputation: 503
Try this:
$(document).ready(function () {
var sum = 1;
$("#b").on('click', function (event) {
$("#sum").text("aa");
});
});
Upvotes: 0