jQuery Form How to - Select all input elements that are enabled








Question

We would like to know how to select all input elements that are enabled.

Answer


<!--  w  w w .j a v a2s .  c o  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(){
            console.log($("input:enabled").length);
        });
    </script>
  </head>
  <body>
    <form>
        <input type="button" value="Input Button" disabled="disabled"/>
    
        <input type="checkbox">asdf</input>
        <input type="checkbox" />
        <input type="checkbox" />
        <input type="file" />
        <input type="hidden" />
        <input type="image" />
        <input type="password" />
        <input type="radio" />
        <input type="reset" />
        <input type="submit" />
        <input type="text" />
    
        <select><option>Option<option/></select>
        <textarea></textarea>
        <button>Button</button>
    </form>    
    </body>
</html>

The code above is rendered as follows: