Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get web browser element's css style?

Tags:

html

browser

c#

css

I have a page like the 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 output:

System.__ComObject

Why does it output a System.__ComObject type and how do I handle it?

HTML page:

<div id="foo" style="display:block;">
a
</div>
like image 313
Jack Avatar asked Jan 01 '26 14:01

Jack


2 Answers

ele.Style

Will help.

ele.GetAttribute("Style")

won't work because returns string, so it can't say more than that is an object, while ele.Style returns CssStyleCollection.

like image 143
nicael Avatar answered Jan 04 '26 11:01

nicael


var e = document.getElementById('foo');
var css = window.getComputedStyle(e,null).getPropertyValue("display");
alert(css);
like image 32
brunobliss Avatar answered Jan 04 '26 12:01

brunobliss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!