Is there a way to detect if a tag is self closing with JQuery like an image tag? Something dynamic not just an image tag.
if ($('.selector')[0].tagName.toLowerCase()=="img") {
// do something
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you need to distinguish between an element that’s empty vs self-closing? If not, you can use:
But if you’re talking about detecting whether a given HTML tag should be empty or not, no you can’t do that programmatically because you’re not stopped from creating invalid HTML and you need to validate it against a DTD to find out.