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.