HtmlDocument.GetElementById("$id")
I want to use this method to get the element with $id
, but it matches a meta
tag with an attribute which has same value as $id
.
HtmlDocument is like this:
<html>
<head>
<meta name="description" content="">
</head>
<body>
<div id="description"></div>
</body>
</html>
I tried to get tag div
with id of "description":
HtmlElement elem = doc.GetElementById("description");
But I got meta
instead of div
. Why is the meta
tag matching?
Why? Here is an official reference from Microsoft: getElementById method: Returns a reference to the first object with the specified value of the ID or NAME attribute.
Solution: You should avoid name attrib in the body so you can reference tags by id if you use myHtmlDocument.Body.All[id] formula as sharique ansari mentioned.
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With