Accessing the HTML DOM - Finding HTML elements
Accessing an HTML element is the same as accessing a Node.
You can access an HTML element in different ways:
The getElementById() method returns the element with the specified ID:
The following example gets the element with id="intro":
getElementsByTagName() returns all elements with a specified tag name.
The following example returns a list of all <p> elements in the document:
The following example returns a list of all <p> elements that are descendants (children, grand-children, etc.) of the element with id="main":
If you want to find all HTML elements with the same class name. Use this
method:
The example above returns a list of all elements with class="intro".
NOTE: getElementsByClassName() does not work in Internet Explorer 5,6,7, and 8.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.