Reputation:
Trying to do something super basic which doesn't seem to work:
HTML
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
</head>
<body>
<button style="margin: 10px; color:white; background-color: #4CAF50; font-size:40px;" type="button" id="aaa" > גבע</button>
</body>
JS
$("aaa").click(function () {
$(this).css('backgroundcolor', 'white');
});
The button color doesn't seem to change. What am I doing wrong?
Thanks!
Upvotes: 1
Views: 105
Reputation: 3
for id use '#' and for 'backgroundcolor' use 'background-color'
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
Upvotes: 0
Reputation: 670
button
is an id selector #aaa
.
<html>
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
</head>
<body>
<button style="margin: 10px; color:white; background-color: #4CAF50; font-size:40px;" type="button" id="aaa" > גבע</button>
<script>
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
</script>
</body>
</html>
<script>
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
</script>
Upvotes: 1
Reputation: 12959
1) Change
$("aaa")
To$("#aaa")
: Forid
selector must use#
sign.2)Change
backgroundcolor
Tobackground-color
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<button style="margin: 10px; color:white;background-color: #4CAF50; font-size:40px;" type="button" id="aaa" > גבע</button>
Upvotes: 0
Reputation: 26
$(this).css("background-color", "yellow");
replace "backgroundcolor"
attribute to "background-color"
Then it will work!
Good luck
Upvotes: 0
Reputation: 115222
Two bugs are there
#
before the id selector which is missing in your code.background-color
or backgroundColor
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button style="margin: 10px; color:white; background-color: #4CAF50; font-size:40px;" type="button" id="aaa" > גבע</button>
<script>
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
</script>
Upvotes: 0
Reputation: 9043
$('.thing').on('click', function() {
$(this).css('background', 'red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class='thing'>button</button>
$('#aaa')
You need to target the element by id in your case.
Upvotes: 1
Reputation: 2038
For id use #
for class use .
in selector
$("#aaa").click(function () {
$(this).css({'background-color':'white'});
});
Upvotes: 0
Reputation: 2109
Replace your code with:
$("#aaa").click(function () {
$(this).css('backgroundColor', 'white');
});
There is a problem with your selector rule, you are missing "#"
Upvotes: 0
Reputation: 50291
Two changes required
#
in jquerybackgroundColor
to backgroundColor
or background-color
$("#aaa").click(function() {
$(this).css('backgroundColor', 'white');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button style="margin: 10px; color:white; background-color: #4CAF50; font-size:40px;" type="button" id="aaa"> גבע</button>
Upvotes: 1