Change Background color (css property) using Jquery
css, html, javascript, jquery
Solution
You're using a colon instead of a comma. Try:
$(body).css("background-color","blue");
You also need to wrap the id in quotes or it will look for a variable called `#co`
$("#co").click(change()
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 -->
<script>
$(document).ready(function() {
$("#co").click(function() {
$("body").css("background-color","blue"); //edit, body must be in quotes!
});
});
</script>
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.
http://jsfiddle.net/CLwE5/ demo fiddle
Problem
I want to Change the background colour on click . This is my code work that i tried.pls help me out :) ``` <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> $(document).ready(function(){ $(#co).click(change() { $(body).css("background-color":"blue"); }); }); ``` Css code ``` body { background-color:red; } ``` Body code ``` <body> <div id="co" click="change()"> hello </div> ```