None
None

Reputation: 5670

exclude a class from jquery for each

My code is like this

$("a[href]").each(function () {
    if ($(this).attr("href").toLowerCase().indexOf("javascript:") != 0 &&     $(this).attr("class") != "to-top")
   {
      $(this).attr("href", new URI($(this).attr("href")).removeQuery("at").addQuery("at", $.cookies.get('ACCT_TYPE') != null ? $.cookies.get('ACCT_TYPE') : "erhverv"));
  }
});

now i want to avoid a specific link from this condition ."a" links comes 'under tax-switch' class. is there any short cuts to achieve this?

Upvotes: 2

Views: 2289

Answers (4)

Richard Parnaby-King
Richard Parnaby-King

Reputation: 14862

As @vivek has said, use the not function:

$('a[href]').not('.tax-switch').each(

This'll select all anchors that do not have the class 'tax-switch'.

Upvotes: 4

rajesh kakawat
rajesh kakawat

Reputation: 10896

try this code , Working fiddle

$("a[href]:not(.tax-switch)").each(function () {
   $("#myDIV").append('<p>'+ $(this).html()+'</p>');
});

Upvotes: 3

David Thomas
David Thomas

Reputation: 253318

Use filter():

$('a[href]').filter(function(){
    return !$(this).hasClass('tax-switch');
}).each(function(){
    // do your stuff
});

References:

  • filter().

Upvotes: 0

Vivek Goel
Vivek Goel

Reputation: 24150

You can user jquery not selector. http://api.jquery.com/not-selector/

Upvotes: 1

Related Questions