Common selectors, attributes, and methods in JS are called.

Source: Internet
Author: User

Common selectors, attributes, and methods in JS are called.

Use selector, attribute, and method call together:

<Style> # a {width: 200px; height: 100px; background-color: red ;}. B {width: 200px; height: 100px; background-color: green ;}. div1 {width: 200px; height: 100px; background-color: aqua ;} </style> <body> <div id = "a"> </div> <div class = "B" style = "background-color: black; "> </div> <div class =" B "style =" background-color: chartreuse; "> </div> <div class =" div1 "> elite education </div> <input type =" text "name =" ipt1 "/> <Input type = "checkbox" name = "ckb2"/disabled = "disabled"> </body> <script> // first select the element to add the effect. // ID selector (Use relatively high JS) var a = document. getElementById ("a"); // detection type alert (typeof (document. getElementById ("a"). style. backgroundColor = "royalblue";. innerHTML = "<span> hello <span>";. innerText = "<span> hello <span>"; // class selector var B _class = document. getElementsByClassName ("B"); B _class [0]. style. backgroundColor = "red"; Var B _class = document. getElementsByClassName ("B"); B _class [1]. style. backgroundColor = "blueviolet"; // tag selector var B _ B = document. getElementsByTagName ("div"); B _ B [1]. style. backgroundColor = "yellow"; var div_1 = document. getElementsByName ("ipt1"); div_1 [0]. value = "text box"; var ckb2 = document. getElementsByName ("ckb2") [0]; ckb2.setAttribute ("checked", ""); // remove the ckb2.removeAttribute ("disabled") // create the element var A = document. createElement ("a");. setAttribute ("href", "http://www.baidu.com");. innerText = "Baidu"; document. body. appendChild (a); document. body. removeChild (a); div1.appendChild (a); </script> <body> <! -- DOM Document Object Model BOM Bowers o m --> <div id = "div1" class = "div1"> </div> <div class = "div1"> </div> <input type = "text" name = "ipt1"/> <input type = "checkbox" name = "ckb1" disabled = "disabled"/> </body> 

The commonly used selectors, attributes, and method calls in JS are all the content shared by Alibaba Cloud. I hope to give you a reference and support for the customer's house.

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.