Using jquery or JS how do i check if an object is a div or a li?
`nodeName` is a better choice.http://www.quirksmode.org/dom/w3c_core.html#t23
J-P
2010-04-09 11:40:15
+4
A:
Here's a quick example:
$("div, li").click(function() {
alert(this.nodeName);
});
There are some differences (mainly IE, surprised?) between tagName and nodeName. The few that matter can be found here.
Nick Craver
2010-04-09 11:29:41
@Ian - Undelete! Your's is a perfectly valid answer, just posting this so people know of some odd cases between the two as well :)
Nick Craver
2010-04-09 11:33:49
@Nick - done. I just hate to think of someone using something which didn't work across browsers. jQuery FTW!
Dead account
2010-04-09 11:36:54
+3
A:
Using jQuery:
jQuery(someElement).is('li'); // => return true if it's an <li>
jQuery(someElement).is('div'); // => returns true if it's a <div>
J-P
2010-04-09 11:41:08