getElementById (): The purpose of the method is to look for an element with a given id attribute worth:
element = document.getElementById (ID);
This method returns a node with the given ID attribute that is worth the element. If such an element does not exist, he returns null. This method can only be used for document objects.
The element node returned by the getElementById () method is an object that has properties such as NodeName, NodeType, ParentNode, Childnode, and so on.
The following example extracts the element with the ID zodiac value as FinePrint and saves it in the message variable. The parent node of the message element node is also an element, which we extract into the variable container:
var message = document.getElementById ("FinePrint"); var container = Message.parentnode;
If you are going to extract an element with an ID, then retrieving it with the getElementById () method will be the simplest and quickest method, and once you find this element, you can use SetAttribute (), CloneNode (), AppendChild (), and so on.
In the following example, we first find out that the id attribute value is an element of fineprint, save it to the message variable, and then refresh the title property of this element to this is important
var message = document.getElementById ("FinePrint"); Message.setattribute ("title", "This is imortant ");
In the same document, the ID attribute values of the different elements must vary, and if more than one element has the same Id,getelementbyid () method The behavior will not be expected.
getElementById ()