HTMLElement test
A simple test to determine if a given javascript object is of HTMLElement type
by davidhong
HTML
<div id="container">
<custom></custom>
<header>
<h1>Hello</h1>
<nav>
<ul>
<li><a href="#sitemap">Sitemap</a></li>
</ul>
</nav>
</header>
<article>
<p><code><article></code> is <em>empty</em></p>
</article>
</div>
JavaScript
$(function() {
var isHtmlElement = function(element) {
return ('number' === typeof element.nodeType && element.nodeType > 0);
};
var $p = $('p'),
$custom = $('custom'),
test = function(element) {
console.log(isHtmlElement(element));
};
test($p[0]);
test($custom[0]);
});