property: is a general term for the relationship between the nature of an object and an object. Tags in HTML can have attributes, and attributes provide additional letters to HTML elements.
A property is always in the form of a name/value pair, such as: Name= "value".
Property values are always included in quotation marks. Double quotation marks are the most common, in some cases, such as the property value itself contains double quotes, you must use single quotation marks,
Attributes are always specified in the start tag of an HTML element.
Property instance
HTML links are defined by the <a> tag. The address of the link is specified in the href attribute:
< a href= "http://www.baidu.com" > A </a>
<H1 align= "Center" > has additional information about alignment.
<body> defines the body of the HTML document.
<body bgcolor= "Yellow" > has additional information about the background color.
<table> define HTML tables.
<table border= "1" > has additional information about the table border.
Operations on attributes
1. Locate the element by locating it in the variable.
var a = document.getElementById ("id")
2. Manipulate the attributes of this element
a.setattribute ("attribute name", "attribute value");--Add change properties
a.getattribute ("attribute name");--Get the value of the property
a.removeattribute ("attribute name");--Remove attribute--the latest property will overwrite the original attribute does not appear 2 identical Properties example build button with background color div, click button Background color Change
"Text/css">. div {width:100px; height:100px; Background-color:red; float: Left; Margin-right:10px; } </style>"Button"Value="Validation"Id="BTN1"/><br/> <divclass="Div"Aa="1"></div> <divclass="Div"Aa="1"></div> <divclass="Div"Aa="0"></div> <divclass="Div"Aa="0"></div> <divclass="Div"></div> <divclass="Div"></div></body>"Text/javascript">document.getElementById ('BTN1'). onclick =function () {varOdivs = Document.getelementsbyclassname ('Div'); for(vari =0; i < odivs.length; i++) { if(Odivs[i].getattribute ('AA') =='1') Odivs[i].style.backgroundcolor="Blue"; if(Odivs[i].getattribute ('AA') =='0') Odivs[i].style.backgroundcolor="Green"; } }</script>
View Code
JS Dom Operation (ii) Window.docunment Object--Operation properties