jQuery Examples - $("li:not(.myclass)")



Description

"T:not(.classname)" selects all the elements which have a tag name of T and not having class as classname.

Syntax

Here is the simple syntax to use this selector −

$('tagname:not(.classname)')

Parameters

Here is the description of all the parameters used by this selector −

  • tagname − Any standard HTML tag name like div, p, em, img, li etc.

  • :not(.classname) − not selector, select all element which do not match the selector.

  • .classname − style class applied on the element.

Returns

Like any other jQuery selector, this selector also returns an array filled with the found elements.

Example

Following example would select all the li elements which do not have CSS as big and will apply yellow color to their background.

<html>
   <head>
      <title>The Selector Example</title>
      <script type = "text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            /* Selects all elements matched by <li> that do not have class="big".*/
            $("li:not(.big)").css("background-color", "yellow");
         });
      </script>
   </head>
   
   <body>
      <ul>
         <li class="big">This is first list item of the DOM.</li>
         <li class="medium">This is second list item of the DOM.</li>
         <li class="small">This is third list item of the DOM.</li>
      </ul>
   </body>
</html>

This will produce following result −

jqueryexamples_selectors.htm
Advertisements