How do I check if $(this)
is a div
, ul
or blockquote
?
For example:
if ($(this) is a div) {
alert(\'
Some of these solutions are going a bit overboard. All you need is tagName
from regular old JavaScript. You don't really get any benefit from re-wrapping the whole thing in jQuery again, and especially running some of the more powerful functions in the library to check the tag name. If you want to test it on this page, here's an example.
$("body > *").each(function() {
if (this.tagName === "DIV") {
alert("Yeah, this is a div");
} else {
alert("Bummer, this isn't");
}
});