rboarman
rboarman

Reputation: 8214

jQuery selector for an href without a class

How do I change this selector to only call my function if the target does NOT have a specific class on it ('noscroll' as shown below)?

$('a[href^="#"]').live('click', navigation.smoothScroll);

<a class="noscroll" href="#">My Link</a>

Something like this (psuedo code):

if (!($this).hasClass('noscroll'))
   ($this).live('click', navigation.smoothScroll);

Upvotes: 1

Views: 165

Answers (2)

John Hartsock
John Hartsock

Reputation: 86882

use the :not() selector

$('a[href^="#"]:not(.noscroll)').live('click', function () {
  //your code here
});

Upvotes: 1

Gabe
Gabe

Reputation: 50493

You can use .not()

$('a[href^="#"]').not('.noscroll').live('click', navigation.smoothScroll);

Upvotes: 2

Related Questions