Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:55:31+00:00 2026-06-07T23:55:31+00:00

How do I get all the divs ids on a html page using Html

  • 0

How do I get all the divs ids on a html page using Html Agility Pack. I am trying to get all the ids and put them into a collection.

<p>
    <div class='myclass1'>
        <div id='f'>
        </div>  
        <div id="myclass2">
            <div id="my"><div id="h"></div><div id="b"></div></div>
        </div>
    </div>
</p>

Code:

HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); 
htmlDoc.OptionFixNestedTags=true;
htmlDoc.Load(filePath);    
HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("div"); 

How do I get collection of all divs ids?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:55:33+00:00Added an answer on June 7, 2026 at 11:55 pm

    If you just want the ID’s, you can get a collection of those id attribute nodes instead of getting a collection of the div element nodes. For instance:

    List<string> ids = new List<string>();
    foreach(XmlNode node in doc.SelectNodes("//div/@id"))
    {
        ids.Add(node.InnerText);
    }
    

    This will skip the div elements that don’t have an ID, such as the <div class='myclass1'> element in your example.

    "//div/@id" is an XPath string. XPath is a technology which is vary handy to learn if you deal much with XML, or in this case, HTML via the agility pack library. XPath is an industry standard which allows you to select matching nodes in an XML document.

    • // means you want it to select the following node as a child of the current node, or in any of its descendants. Since the current node is the root node of the document, this will find matching nodes anywhere in the document.
    • div is an element name we want to match. So, in this case, we are telling it to find all div elements anywhere in the document.
    • / indicates that you want a child node. In this case the id attribute is a child of the div element, so first we say we want the div element, then we need the forward slash to say we want one of the div element’s child nodes.
    • @id means we want to find all the id attributes. The @ symbol indicates that it is an attribute name instead of an element name.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get all div's within a page using jQuery including nested
One div works fine, however when using multiple divs they all get expanded simultaneously.
I am wanted to get the id's of all the divs on my page
I'm trying to get a jQuery UI Accordion, with initially all divs collapsed. The
Right now my DOM has three divs with data-roll=page , all of them have
To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts
I am trying to get all Books from the server (local PHP script), that
I'm trying to get all downloads from an repo on github with help of
I want to get all the Calendars, which are in my GoogleAccount, using the
Is it possible to get all 7 days for a given date using linq

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.