Change Background color (css property) using Jquery


I want to Change the background colour on click . This is my code work that i tried.pls help me out :)

   <script src="">



Css code


Body code


    <div id="co" click="change()">



This question is tagged with javascript jquery html css

~ Asked on 2014-01-05 11:05:18

The Best Answer is


You're using a colon instead of a comma. Try:


You also need to wrap the id in quotes or it will look for a variable called #co


There are many more issues here. click isn't an HTML attribute. You want onclick (which is redundant). Try this:

<div id="co"> <!-- no onclick method needed -->
$(document).ready(function() {
    $("#co").click(function() {
        $("body").css("background-color","blue"); //edit, body must be in quotes!

You were trying to call an undefined method. It looks like you were trying to declare it inside the callback statement? I'm not sure. But please compare this to your code and see the differences. demo fiddle

~ Answered on 2014-01-05 11:06:20


Try this


~ Answered on 2014-09-06 05:28:03

Most Viewed Questions: