Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is DOMElement renderable?

Is there a way to check if an Element is renderable ?

for example, i want some method to return true on br a div body html etc

but to return false on head style script etc

i tried if(!el.style) return false; but it seems even head and style have .style

is it at all possible or should i just make a list of renderable tagnames ?

like image 701
n00b Avatar asked Jul 04 '26 00:07

n00b


2 Answers

I think I have a simple solution. Check which elements have display: none at creation.

JsFiddle here

function isDefaultVisible(domElement) {
    var el = document.createElement(domElement.tagName);
    return window.getComputedStyle(el,null).getPropertyValue('display') != 'none';
}
like image 118
Marc Diethelm Avatar answered Jul 06 '26 14:07

Marc Diethelm


All elements can be rendered. It really depends on the browser's default stylesheet. Refer to this great article for more information:

http://mathiasbynens.be/notes/css-hidden-elements

like image 21
user123444555621 Avatar answered Jul 06 '26 13:07

user123444555621



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!