Mark Alexa Mark Alexa - 1 month ago 8
jQuery Question

Changing css property via jQuery

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>

Answer

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"});
     });
});