JavaScript Element Object

Source: Internet
Author: User

Properties of the Action element

<span style= "Font-family:courier new;font-size:14px;" ><body>    <ul id= "City" >    <li id= "BJ" > Beijing </li><li id= "TJ" > Tianjin </li>< Li id= "NJ" > Nanjing </li>    </ul>  </body></span>
1. Get the attribute name of the element

<span style= "Font-family:courier new;font-size:14px;" ><script type= "Text/javascript" >  //Get the Name property value of Beijing node in the page//1 get Beijing node var bjelement = document.getElementById ( "BJ");//2 gets the name property of the Beijing node var arr = Bjelement.name;var arr = bjelement.getattribute ("name");</span>
<span style= "Font-family:courier new;font-size:14px;" ></script></span>
* In actual development, use the ". Attribute name" or the GetAttribute () method?
* * ". Property name": Some browsers do not support it.
* * GetAttribute (attribute name) method: Almost all browsers are supported.
* * Recommended use of the GetAttribute () method.

2. Setting property values for property names

Set the Name property for the page Beijing node: name= "Beijing"//1 get beijing node var bjelement = document.getElementById ("BJ");//2 Set the property Bjelement.setattribute ("name", "Beijing");
3. Remove the properties of a label

<span style= "Font-family:courier New;" >//Delete the name attribute Bjelement.removeattribute ("name") of the Beijing node in the page;</span>






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JavaScript Element Object

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.