getElementsByClassName

Jump to: navigation, search

getElementsByClassName


W3C Candidate Recommendation

Summary

Gets a collection of all descendant elements with given classes. Not recommended; see Notes.

Method of dom/HTMLElement

Syntax

var elements = element.getElementsByClassName(classNames);

Parameters

classNames

Data-type: String


A space separated list of classes.

Return Value

Returns an object of type Object.

A live HTMLCollection of elements with the given class names.

Needs Examples: This section should include examples.

Usage

The use of this property is discouraged. See the Notes section for details.

Notes

The use of this property is discouraged, due to the performance implications (due to the live DOMCollection where any changes to the document must be reflected on the returned object immediately) and complexity (the removal of an element from the document will result in immediate changes to the collection).

A close alternative is


Related specifications

Specification Status Related Changes
W3C HTML5 Candidate Recommendation Section 3.1.1

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support Supported (when?)
3
9
9.5
3.1

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]