JQuery Selector text

From CoderLearner
Jump to: navigation, search

Description

Select all elements that have the [type="text"].

Syntax

$("input[type='text']")

Example 1

<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>
      <style>
         .text_input {
            width:150px;
            height:30px;
            font-size: 25px;
            background-color: #999900;
         }
      </style>
      <script>
         $().ready(function() {
            $('form#mmm input[type="text"]').addClass("text_input");
         });
      </script>
   </head>
   <body> 
      <div></div>
      <form id="mmm">
         <table border="0">
            <tr>
               <td>First Name:</td>
               <td>
                  <input type="text" name="first_name" size="20" maxlength="20"/>
               </td>
            </tr>
            <tr>
               <td>Middle Name:</td>
               <td>
                  <input type="text" name="middle_name" size="20" maxlength="20" />
               </td>
            </tr>
            <tr>
               <td>Last Name:</td>
               <td>
                  <input type="text" name="last_name" size="20" maxlength="20" />
               </td>
            </tr>
            <tr>
               <td>Tel/Phone:</td>
               <td>
                  <input type="text" name="phone" size="20" maxlength="20" />
               </td>
            </tr>

            <tr>
               <td>Login Name:</td>
               <td>
                  <input type="text" name="lg_name" size="20" maxlength="20" />
               </td>
            </tr>
            <tr>
               <td>Password:</td>
               <td>
                  <input type="password" name="password1" size="20" maxlength="20" />
               </td>
            </tr>
            <tr>
               <td>Confirm:</td>
               <td>
                  <input type="password" name="password2" size="20" maxlength="20" />
               </td>
            </tr>
            <tr>
               <td colspan="2">
                  <input type="submit" name="register" value="Register" />
                  <input type="submit" name="Login" value="Login" />
               </td>
            </tr>
         </table>
      </form>
   </body>
</html>

Try It