Jquery uses css to modify the webpage background color.

Source: Internet
Author: User

When browsing some websites, especially some novel websites, there will be a place to modify the background color of the page. This function is easily implemented using jquery.

:
 
Show you code:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> jquery test </title>
<Script src = "jquery-1.11.1.min.js"> </script>
</Head>

<Body>
<Button style = "background-color: white" value = "white"> white </button>
<Button style = "background-color: red" value = "red"> red </button>
<Button style = "background-color: green" value = "green"> green </button>
<Button style = "background-color: yellow" value = "yellow"> yellow </button>
<Div class = "show">
</Div>
<Script>
$ ("Button"). click (
Function ()
{
Var color = this. value;
$ ("Body" ).css ("background-color", color );
}
)
</Script>
</Html>

Select the object to be operated: button Based on the element name, use the click method to find the clicked button, and then obtain the corresponding color value of the button in the trigger event, then, the color value is passed in as the property value of background-color through the css () method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.