w3resource

jQuery: Set the background color of a page

jQuery core : Exercise-2 with Solution

Set the background color of a page to red.

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>Set the background color of a page to red</title>
</head>
<body>
  <p>Set the background color of the page to red</p>
</body>
</html>

JavaScript Code:

$(document.body).css( "background", "red" );

Live Demo:

See the Pen jquery-core-exercise-2 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Find all h1 elements that are children of a div element and apply a background to them.
Next: Hide all the input elements within a form.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/jquery-exercises/jquery-core-exercise-2.php