JavaScript first to talk about the JS operation CSS

Source: Internet
Author: User

It was supposed to be the CSS that controls the width and background color of the div in the HTML, but the JavaScript was used below to recall the div box and overwrite the original CSS property content.

Demand target: A 100-pixel pink background div box turns into a 300-pixel orange-colored div box

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">div{Background:pink; <!--background color: pink--width:100px; <!--width: 100 pixels--height:100px; <!--height: 100 pixels--}</style><!--JavaScript code can only be written in the tag body of the script below--><script>//Way One:    //find the label with the ID div and continue looking for the style property    //document.getElementById (' txt '). style.width= ' 300px ';    //document.getElementById (' txt '). style.height= ' 300px ';    //document.getElementById (' txt '). style.background= ' Orange ';    //Way Two:    //find the element with the ID txt first, put it in a variable, this process can be understood as the right side of the result is assigned to the left    vart = document.getElementById (' txt '); //T is the variable name, which represents the location of the HTML box        //sets the width of the box's style to 300 pixelsT.style.width= ' 300px '; //sets the height of the box's style to 300 pixelst.style.height= ' 300px '; //set the background color in the box's style to orangeT.style.background= ' Orange ';</script>

After running the following:

JavaScript first to talk about the JS operation CSS

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.