jQuery Selector How to - Select an element which doesn't have a specific class name








Question

We would like to know how to select an element which doesn't have a specific class name.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   w  w w . j  av  a 2 s . c o  m-->
    $('a[class!="active"]').css('color','green');
});
</script>
</head>
<body>
  <a href="">asdf</a>
  <a class="active" href="">asdf</a>
  <a href="">asdf</a>
</body>
</html>

The code above is rendered as follows: