jQuery Selector How to - Select elements that don't have the specified attribute








Question

We would like to know how to select elements that don't have the specified attribute.

Answer


<!--   w  ww .  jav a  2 s.co  m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name!='n']").val(" not n");
        });
    </script>
  </head>
  <body>
    <body>
      <input type="text" name="newsletter" value="Hot Fuzz" />
    </body>
</html>

The code above is rendered as follows: