Document.getelementbyid/name/tagname

Source: Internet
Author: User

document.getElementById1, getElementById

Function: The ID in the General page is unique and is used to prepare an element for positioning
Syntax: document.getElementById (ID)
Parameter: ID: Required option is string
return value: Object; Returns the first in the same ID object, in the order in which the page appears, or null if there are no eligible objects

Example
document.getElementById ("Id1"). Value;

2, Getelementsbyname

Function: Finds an array of elements of the same name by the names of the elements
Syntax: Document.getelementsbyname (name)
Parameter: Name: Required option is string
Return value: Array object;            If there are no eligible objects, an empty array is returned, in the order in which they appear in the page note: Returns the value of the array value as the Values property, and if a label has no Value property, when you add the Value property and assign a value, Getelementsbyname can also fetch its value.             When no value is assigned to the Value property, Getelementsbyname returns the array value undefined, but still gets the number of the same name label Document.getelementsbyname (name). length Document.getelementsbyname can still be used when the Name property is not set, it will take the value of the property based on your ID

Example
Document.getelementsbyname ("name1") [0].value;
Document.getelementsbyname ("name1") [1].value; <span id= ' cbylawindexname ' class= ' normalnode ' value= ' all ' > All </span> ' <span id= ' Cbylawindexname ' class = ' Normalnode ' value= ' all > Full </span> ' span tag does not actually have the name and Value property but Document.getelementsbyname ("Cbylawindexname ") will still get the value

3, getElementsByTagName

Function: Query by HTML tag name, return an array of the same tag element
Syntax: Object.getelementsbytagname (tagname) object can be document or event.srcElement.parentElement, etc.
Parameter: tagname: The required option is a string, which is retrieved according to the HTML tag.
Return value: Array object; If there are no eligible objects, an empty array is returned, in the order in which they appear in the page

Example
document.getElementsByTagName ("P") [0].childnodes[0].nodevalue;
document.getElementsByTagName ("P") [1].childnodes[0].nodevalue

Document.getelementbyid/name/tagname

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.