1

In a C# WinForms application I'm using a Web browser control in which i view some HTML designs.

I could change html element attributes through code then edit.

However, i could not clone html element to re-add them to html page again. I tried following code :

            HtmlElement old_element = WebBrowser1.Document.GetElementById("element1");
            HtmlElement new_element = my_element;
            new_element.Style = "background-color:orange;";
            my_element.Parent.InnerHtml += new_element.OuterHtml;

When running code background color is applied to both old_element and new_element.

I want changes to be applied only to new_element while preserving old element as it is.

Is that possible without dealing with element html as text ?

jazb
  • 5,498
  • 6
  • 37
  • 44
EgyEast
  • 1,542
  • 6
  • 28
  • 44
  • What you are doing atm is passing down reference with `HtlmElement new_element = my_element;` this doesn't create a new object and thats why changes apply to both. this is a duplicate of [Deep cloning objects](https://stackoverflow.com/questions/78536/deep-cloning-objects) – H.Mikhaeljan Nov 08 '18 at 08:37
  • I just was trying to explain what i wanna do. Tried this solution but it gives error that this object cannot be serialized – EgyEast Nov 08 '18 at 13:23
  • It seems that it doesn't work with HTMLElement – EgyEast Nov 08 '18 at 14:21

0 Answers0