I’m trying to highlight all links that do not have a href set, or if it is blank. I wrote the following: http://jsfiddle.net/nSMEf/
$(document).ready(function() {
if ($('.green').attr("href") == "" || typeof $('.green').attr("href") === 'undefined'){
$('.green').attr('class', 'yellow');
}
if ($('.blue').attr("href") == "" || typeof $('.blue').attr("href") === 'undefined'){
$('.blue').attr('class', 'yellow');
}
});
I noticed that the if statement seemed to apply only on which link came first, and all the following links would be styled the same. The second “blue” group is the same as the first but with the order switched.
My approach clearly isn’t right. Is it possible to have the yellow class applied conditionally (based if the href is blank or not there) on each element?
would this help
Updated jsfiddle: http://jsfiddle.net/nSMEf/3/
Editing above code according to suggestion in comments