JQuery Selector has attribute selector

From CoderLearner
Jump to: navigation, search

Description

Select elements that have a specific attribute with any values.

Syntax

$('input[id]')

$('span[id]')

$('div[id]')

Example 1

<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>

      <script>
         $().ready(function() {
            $('input[id]').val('Contain ID');
         });
      </script>
   </head>
   <body> 
      <form>
         <input type="text" name="uimage"/><br/>
         <input type="text" name="desc" id="check1"/><br/>
         <input type="text" name="yimage"/><br/>
         <input type="text" name="ydesc" id="make1"/><br/>
      </form>
   </body>
</html>

Try It