Reputation: 125
What I'm trying to achieve here is when I hover over the link it would turn green.
What is exactly wrong with this code:
<script>
$(document).ready(function() {
$("a").hover(function() {
$(this).css({"background-color": "green;"});
});
});
</script>
Upvotes: 1
Views: 45
Reputation: 3045
jQuery having .css() function which will allow you to change CSS property or any DOM Element on document.
Single Property Example:
jQuery(Selector).css("PropertyName", "Value");
Multiple Property Example:
jQuery(Selector).css({"PropertyName1": "Value1", "PropertyName2": "Value2"});
e.g.
jQuery(document).ready(function() {
jQuery("a").hover(function() {
jQuery(this).css("background-color", "green");
});
});
Upvotes: 0
Reputation: 318352
It's the semicolon after green;
, that works in CSS, but not in javascript, which expects a color only, no semicolon.
$(document).ready(function() {
$("a").hover(function() {
$(this).css({"background-color": "green"});
});
});
Upvotes: 1