Home > Web Front-end > JS Tutorial > body text

jquery changes the background color of web pages through css method_jquery

WBOY
Release: 2016-05-16 16:45:56
Original
1450 people have browsed it

When we browse some websites, especially some novel websites, there will be a place to modify the background color of the page. This function is easy to implement using jquery.

Rendering:
jquery changes the background color of web pages through css method_jquery
show you code:

Copy code The code is as follows :





< title>jquery test



< body>





<script> <br>$("button").click( <br>function() <br>{ <br>var color = this.value; <br>$("body").css("background-color",color); <br>} <br>) <br></script>


We first select the object we want to operate based on the element name: button, then use the click method to find the clicked button, and then Get the corresponding color value of the button from the triggered event, and then pass the color value as the attribute value of background-color through the css() method.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template