jQuery: Only if class does not match

hankknight
hankknight used Ask the Experts™
on
$(this).find("em").css({'background-position': $(this).find("em").css("background-position").match(/([^\s]+)/)[0] + ' 0'});

Open in new window

I don't want to do this if the class of this is "selected"

For example, it should apply to this:
          <a href="#" class="hello selected"><em>Hello</em></a>

But not this:
          <a href="#" class="hello"><em>Hello</em></a>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
use "not" selector : http://api.jquery.com/not-selector/

$(this).not(".selected").find("em").css({'background-position': $(this).find("em").css("background-position").match(/([^\s]+)/)[0] + ' 0'});
 
leakim971Multitechnician
Top Expert 2014

Commented:
Thanks for the points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial