ElementGetElementsByTagName Method

Returns HTMLCollection object containing all elements with a given tag name, in document order.

Namespace: Aspose.Html.Dom
Assembly: Aspose.HTML (in Aspose.HTML.dll) Version: 22.1
public HTMLCollection GetElementsByTagName(
	string name


Type: SystemString

The tag name. String representation of tag name.

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 input 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

    HTMLCollection htmlCollection = document.GetElementsByTagName("p");
    Console.WriteLine($"Found: {htmlCollection.Length}" );
    foreach (Element element in htmlCollection)

    // User code goes here

*inputHtmlPath - user input html file.

# Console output

Found: 3

The paragraph styled pStyle class content...

The second paragraph content...

The third paragraph content...

See Also