jquery check if attribute exists code example
Example 1: jquery if attribute
if ( $('html').attr('lang') == 'fr-FR' ) {
// do this
} else {
// do that
}
Example 2: jquery check if attribute exists
var attr = $(this).attr('name');
// For some browsers, `attr` is undefined; for others,
// `attr` is false. Check for both.
if (typeof attr !== typeof undefined && attr !== false) {
// ...
}
Example 3: how to check element has an attribute js
let result = element.hasAttribute(name);