Very simple question...
for
$('a')
How do I test if that jQuery object has an HREF attribute? I'm Looking for something that will return true or false that I can use in an if() statement.
Thanks!
jQuery's .attr() function will return undefined if the attribute to be found is missing in the selected element(s).
if($('a').attr('href') === undefined) {
// Element 'a' has no href
}
Note: There are other ways to test for undefined.
if ($('a').not($('a:link')).length) {
//you have `<a>` elements that are placeholders only
}
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