JS Dom Operation (ii) Window.docunment Object--Operation properties

Source: Internet
Author: User

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

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.