How do I get the CSS styling of a CSS element?

I have a page like below in my web browser that I want to get the style

atributte value . I tried:

 HtmlElement ele = webBrowser1.Document.GetElementById("foo");
            MessageBox.Show(ele.GetAttribute("style"));

      

but it outputs:

System.__ComObject

      

Why does it infer the type System.__ComObject

and how to handle it?

HTML page:

<div id="foo" style="display:block;">
a
</div>

      

+3


source to share


2 answers


ele.Style

      

Help.



ele.GetAttribute("Style")

      

won't work because it returns a string, so it can't say more than an object, but ele.Style

returns CssStyleCollection

.

+3


source


var e = document.getElementById('foo');
var css = window.getComputedStyle(e,null).getPropertyValue("display");
alert(css);

      



+3


source







All Articles