JavaScript uses the element ID and name to set the style. javascriptname

Source: Internet
Author: User

JavaScript uses the element ID and name to set the style. javascriptname

1. Description

(1) return the reference or node of the provided element based on its id value.

document.getElementById("tr_th")

(2) return a reference or node for a group of elements based on the tag in the parameter.

document.getElementsByTagName("td")

2. Source Code

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

3. Implementation result

(1) During Initialization

(2) Click "set color ".


Set html Element Content in javascript

<Div id = "name"> <p> nihao </p> </div>
<Script type = "text/javascript">
Var v = document. getElementById ("name ");
Alert (v. innerHTML + "\ n will be modified after confirmation"); // v. innerHTML Value
V. innerHTML = "<p> hello, modified! </P> "; // v. innerHTML = Modify the value
</Script>

Javascript id and name

Id is a unique identifier, that is, only one element is allowed to use this id in an html document or DOM. In javascript, you can use document. getDocumentById (). This method returns a unique result.
Name is not a unique identifier, for example, radio in your form, that is, multiple use the same name. For the name element, you can use document. getElementByName (). An array is returned. to obtain the first element, you can use document. getElementByName ("name") [index.

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.