Removing HtmlElement objects programmatically using C#
Solution 1
Look at this WebControl Heritance, with loads of feature: http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
You could add a remove method to del element by id.
Hope this helps
Solution 2
You can delete the element by setting its outerhtml to an empty string.
elem.OuterHtml = ""
I hope this is what you were looking for.
gm
Solution 3
The only other way I know is to change the parent's InnerHtml
.
Solution 4
There's a method called IHTMLDOMNode::removeNode
which looks like the "official" way to do this, but this is unmanaged code in mshtml.dll
. I'm looking for something more suitable for C#.
Tony the Pony
Updated on July 06, 2022Comments
-
Tony the Pony almost 2 years
In a
WebBrowser
control, how do I removeHtmlElement
objects? There are no methods in theHtmlElement
class to accomplish this. As a workaround, I can create a "dummy"HtmlElement
(without inserting it into theHtmlDocument
), into which I then insert (viaAppendChild
) theHtmlElement
objects to be removed. This feels like a hack. Is there a better way to do this?P.S. I want to retain the
HtmlElement
in memory to be used later, not simply destroy it (which is what setting its parent'sinnerHtml
to an empty string would do) -
user38329 about 13 yearsDoesn't [always] work with Internet Explorer 6. The BASE tag, for instance, resists this method.