views:

190

answers:

1

I use the following code to select all external links on the page

items = jQuery("a[href^=\'http:\']").not("[href*=\'" + window.location.host + "\']");

But I need to exclude links from tags with some known classes, e.g. I want to exclude "class1" and "class4" and select whatever have left.

<body>
<div>
  <p class="class1">
    <span class="class2"><a href="#">link</a></span>
    <span class="class2"><a href="#">link</a></span>
  </p>
</div>
<p class="class3"><a href="#">link</a></p>
<div class="class4"><a href="#">link</a></div>
<a href="#">link</a>
</body>

Thanks in advance

+1  A: 

Html elements can have multiple classes by seperating each class name with a space. Is it not possible to just add an additional class name to the elements you want to select, and not add it to the ones you don't want to select?

Jeremy
Seems like a perfectly valid and logical solution to me.
Flash84x
There would be no problems if the target elements were marked. The script should skip links from e.g. <div class="navigation"> tag.
Alex