-1

thanx in advance for replies

trying to addclass() for all href's with <a> tag

and want to exclude href contains example1.com , example2.com , example3.com

but i have tried a lot with

var exclude = ["example1.com","example2.com","example3.com"];

$('a.class').has('a[href='"+exclude+"']').removeClass('class');

or

$('a.class').has('a:contains('"+exclude+"')').removeClass('class');

but all class removed

hope to help me

2 Answers2

0

You can use the array elements to create the selector for targeting elements :

$("a[href*='" + exclude.join("'],[href*='") + "']").removeClass('class');

Working Demo

You do not need to perform both addClass and removeClass. You can use above selector along with .not() to filter them out:

$('a').not($("[href*='" + exclude.join("'],[href*='") + "']")).addClass('class');

Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
-1
 $("a.class").each(function(n){
    $(this).attr("href" , exclude[n]).removeClass('class');
 }
Rajiv007
  • 1,126
  • 7
  • 13