Element.GetElementsByTagName method

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

public HTMLCollection GetElementsByTagName(String name)
nameStringThe tag name. String representation of tag name.

Return Value

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
import System;
import com.aspose.html;
import com.aspose.html.Collections;
import com.aspose.html.Dom;
import (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