Learning getElementByTagsName and related functions

Source: Internet
Author: User
GetElementByTagsName

Syntax:
ArrElements = object. getElementByTagsName (sTagName); parameters:
STagName: required. String (String ).

Return Value:
ArrElements: Array ). If no matching object exists, an empty array is returned.

Note: ObjectGet and return the tag name is equal STagName.
This DOM method is equivalent to the tags method of the all set of DHTML Object Model.

This function is used to obtain all the identical tags in a tag and put these tags in the array (that is, the returned value ).

GetElementById

Syntax: OElement = Document . GetElementById ( SID )Parameters:
SID : Required. String ).
Return Value:
OElement : Object (Element ).
Description: obtains an object based on the specified id property value. The returned id property value is equal SID. If the corresponding object is a group of objects, the first object in the group is returned.
If no matching object exists Null.

GetElementsByName

Syntax: OElements = Document . GetElementsByName ( SName )Parameters:
SName : Required. String ).
Return Value:
OElements : Array ). If no matching object exists, an empty array is returned.
Description: The returned value is the same as the value of name or id. SName.
The array contains only the objects with the name and id attributes. Use the custom (expando) NameThe property object is not obtained.

CreateElement:

Syntax: OElement = Document . CreateElement ( STagName )Parameters:
STagName : Required. String ).
Return Value:
OElement : Object (Element ). Returns the reference of the new object.
Creates a new object instance based on the specified tag.
IE4.0 can only be used to create img, area, and option. You can use IE5.0 to create all object types except frame and iframe.
Attributes of the new object can be read and controlled by the program.
After using this method to create an object, you must explicitly place the object into a collection or document hierarchy before using it.
For input, the default type attribute value is Text, So the new instance is a text input box by default. If you want other types of input, you must set the type attribute when using this method to create an object.
STagNameCan contain attributes, as long as the entire String (String) is valid HTML. If you want to use this method to create an object that contains the name attribute during runtime, you should do so.

AppendChild:

Syntax: OElement = Object . AppendChild ( ONode )Parameters:
ONode : Required. Object (Element ). The object to be added.
Return Value:
OElement : Object (Element ). Returns the reference of the added object.
Note: ONodeAdd Object. That is ObjectThe last entry of the childNodes set.
ONodeMust be created before being added.
The ONodeVisible, it must be within the body object in the document structure.
If ONodeIs an object that has already been located in the document structure. The object will be moved to the specified insert position without any new objects being created.
You can use this method at runtime. If the object is removed before the close tag of the object is resolved, the file space may not be presented. Example: var oNewNode = document. createElement ("div ");
Document. body. appendChild (oNewNode );

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.