ElementGetElementsByClassName Method

Returns HTMLCollection object containing all the elements within element that have all the classes specified in argument.

Namespace: Aspose.Html.Dom
Assembly: Aspose.HTML (in Aspose.HTML.dll) Version: 22.4
public HTMLCollection GetElementsByClassName(
	string classNames


Type: SystemString
The string string that contains an unordered set of unique space-separated tokens representing classes (class names)

Return Value

Type: HTMLCollection

An HTMLCollection object is an array-like list of elements.


Refer to official spec.

You may also be interested in documentation.

You can download the complete examples and data files from GitHub.

# HTML source content
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<div id="divElementContainerId">
    <p class="pStyle">The paragraph styled pStyle class content...</p>
    <p>The second paragraph content...</p>
    <p>The third paragraph content...</p>
    <div class="pStyle">The div element styled pStyle class...</div>

# C# code
using System;
using Aspose.Html;
using Aspose.Html.Collections;
using Aspose.Html.Dom;
using (var document = new HTMLDocument(inputHtmlPath))
    // User code goes here

    Element container = document.GetElementById("divElementContainerId");
    HTMLCollection htmlCollection = container.GetElementsByClassName("pStyle");

    Console.WriteLine($"Found: {htmlCollection.Length}");
    foreach (Element element in htmlCollection)

    // User code goes here

*inputHtmlPath - user input html file path.

# Console output

Found: 2

The paragraph styled pStyle class content...

The div element styled pStyle class...

See Also