How do you check if there is an attribute on an element in jQuery? Similar to hasClass, but with attr?
For example,
if ($(this).hasAttr("name")) {
// ...
}
How do you check if there is an attribute on an element in jQuery? Similar to hasClass, but with attr?
For example,
if ($(this).hasAttr("name")) {
// ...
}
How about just $(this).is("[name]")?
The [attr] syntax is the CSS selector for an element with an attribute attr, and .is() checks if the element it is called on matches the given CSS selector.