James James - 1 month ago 5
jQuery Question

Check, if element is a div

How do I check if

$(this)
is a
div
,
ul
or
blockquote
?

For example:

if ($(this) is a div) {
alert('its a div!');
} else {
alert('its not a div! some other stuff');
}

Answer

Something like this:

if(this.tagName == 'DIV'){
    alert("It's a div!");
} else {
    alert("It's not a div! [some other stuff]");
}