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 ?

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';
}

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


function isElementRenderable(el){
    if(el.nodeType != 1) return false;
    if(el instanceof HTMLHeadElement || el instanceof HTMLLinkElement ||
       el instanceof HTMLTitleElement|| el instanceof HTMLMetaElement ||
       el instanceof HTMLBaseElement || el instanceof HTMLStyleElement||
       el instanceof HTMLScriptElement)
    return false;
    return true;
}

Need Your Help

How to find substring from string without using indexof method in C#?

c# string substring

I want to find the position of a substring in a string if present without using any string method including indexof. I tried so much times but failed. Will anybody tell me how to do in C#? We can use

Decision tree implementation issue in apache spark with java

java machine-learning bigdata apache-spark decision-tree

I'm trying to implement simple demo for decision tree classifier using java and apache spark 1.0.0 version. I base on http://spark.apache.org/docs/1.0.0/mllib-decision-tree.html. So far I've wrote ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.