Home  >  Article  >  Web Front-end  >  jquery changes the background color of web pages through css method_jquery

jquery changes the background color of web pages through css method_jquery

WBOY
WBOYOriginal
2016-05-16 16:45:561446browse

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.
Statement:
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