hasClass not working for some reason...

hasClass not working for some reason...

Hi,

I've been pulling my hair out trying to figure out what is wrong with my code here:

  1. // Add attributes to external links
  2. if($('a').hasClass('notexternal')) {
  3.   // do nothing
  4. } else {
  5.   $("a[href*='http://']:not([href*='"+location.hostname+"']), a[href*='https://']:not([href*='"+location.hostname+"'])").attr('title','External link').attr('rel', 'external');
  6. }

Basically, I'm trying to make any links without the class 'notexternal' and that has an external domain have:

1. A title attribute of 'External link'
2. A rel attribute of external

However, everything within the 'else' part of the statement above doesn't work. I've tried replacing it with other code to test, but I can't get it to respond... can anyone see what I'm doing wrong?

Thanks,

Osu