I want to know that how to get attribute "class" of an html element using webbrowser component in C# .. Normally i am able to get any attribute (except class attribute) of any html tag. but this time i want to get attribute of "class" here is a sample html element
<p class="abstract"> Hello World </p>

Normally i was able to get the attribute of any html tag like
<a href="http://www.anylink.com"> Hello World </a>

String = HtmlElement.GetAttribute("href"); //So it gives me the value of href attribute...

But for this html tag &lt;p class="abstract"&gt; Hello World &lt;/p&gt;

I tried String = HtmlElement.GetAttribute("class");

but it doesnt worked for me :(

Recommended Answers

All 2 Replies

>But for this html tag &lt;p class="abstract"&gt; Hello World &lt;/p&gt;

Use HttpServerUtility.HtmlDecode Method (String) - It decodes an HTML-encoded string and returns the decoded string.

The way I do it is to first add a reference to Microsoft HTML com component then get the class name by using:

string className = ((mshtml.IHTMLElement)element.DomElement).className;

I want to know that how to get attribute "class" of an html element using webbrowser component in C# .. Normally i am able to get any attribute (except class attribute) of any html tag. but this time i want to get attribute of "class" here is a sample html element
<p class="abstract"> Hello World </p>

Normally i was able to get the attribute of any html tag like
<a href="http://www.anylink.com"> Hello World </a>

String = HtmlElement.GetAttribute("href"); //So it gives me the value of href attribute...

But for this html tag &lt;p class="abstract"&gt; Hello World &lt;/p&gt;

I tried String = HtmlElement.GetAttribute("class");

but it doesnt worked for me :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.