Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing HtmlElement objects programmatically using C#

In a WebBrowser control, how do I remove HtmlElement objects? There are no methods in the HtmlElement class to accomplish this. As a workaround, I can create a "dummy" HtmlElement (without inserting it into the HtmlDocument), into which I then insert (via AppendChild) the HtmlElement 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's innerHtml to an empty string would do)

like image 672
Tony the Pony Avatar asked Feb 16 '09 19:02

Tony the Pony


2 Answers

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

like image 75
alexl Avatar answered Oct 28 '22 10:10

alexl


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

like image 37
Gerhard Avatar answered Oct 28 '22 11:10

Gerhard