HTML DOM getElementsByClassName() Method (original) (raw)
Last Updated : 02 Sep, 2024
The **getElementsByClassName() method in Javascript returns an object containing all the elements with the specified class names in the document as objects. Each element in the returned object can be accessed by its index. The index value will start with 0. This method can be called upon by any individual element to search for its descendant elements with the specified class names.
**Syntax:
document.getElementsByClassName(classnames);
**Parameters: This is a required method that takes only one parameter, which is a string containing space-separated class names of the elements that are to be searched for. For searching with multiple class names, it must be separated with space.
**Note: We can use the length property that returns the collection of all HTML elements in a document for the specified class name & then by looping through the HTML elements, we can take the information that wants.
**Example 1: This example describes the getElementsByClassName() method for getting access to an HTML element by its class name.
HTML `
DOM getElementByClassName() Method