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'); }
Use the childNodes property to check if a div element is empty. The childNodes property returns a NodeList of the element's child nodes, including elements, text nodes and comments. If the property returns a value of 0 , then the div is empty.
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute.
Something like this:
if(this.tagName == 'DIV') { alert("It's a div!"); } else { alert("It's not a div! [some other stuff]"); }
Solutions without jQuery are already posted, so I'll post solution using jQuery
$(this).is("div,ul,blockquote")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With