Search code examples
c#htmlgeckofx

Hiding HTML element in GeckoWebBrowser (C#)


I'm trying to make a little program in C# using Gecko; I want to load some webpage in Gecko, search for specific element and hide it to be invisible for user. I wrote that code and it works in WebBrowser (based on IE) but similiar code doesn't work with Gecko. This is what I made in WebBrowser:

HtmlElement h1 = webBrowser1.Document.GetElementsByTagName("h1")[0];
if (h1 != null)
{
   h1.Style = "display:none";
}

I know how to search for element in Gecko but how to make this element invisible?

Thanks, Jakub


Solution

  • The following works in GeckoFX 45. You can use the SetAttribute method to set the style of a given element.

    GeckoHtmlElement someElement = webBrowser1.Document.GetElementsByTagName("h1")[0];
    someElement.SetAttribute("style", @"display: none;");