John M
John M

Reputation: 201

Find all elements that are not disabled

I got html as follows:

    <tr>
        <td><input type="text" ......></input></td>
        <td><select>
                 <option val="1">1</option>
                 <option val="2">2</option>
                 <option val="3">3</option>
            </select>
        </td>
        <td><input type="text" disabled="disabled" ......></input></td>
        <td><select disabled="disabled">
                 <option val="1">1</option>
                 <option val="2">2</option>
                 <option val="3">3</option>
            </select>
        </td>
     </tr>

I would like to find all td's that has textboxes and dropdowns which are not disabled. I'm tryin to do this:

     var res = $.extend({}, $("#myTable").find("td> input:not(:disabled)"), $("#myTable").find("td> 
                                 select:not(:disabled)"));

Is there a better way to do this?

Upvotes: 1

Views: 1008

Answers (1)

Barmar
Barmar

Reputation: 780879

jQuery has a :input pseudo-selector, which encompasses all the different types of user input elements. You can use that instead of having to write separate selectors for input and select.

And you can use :enabled instead of :not(:disabled).

var res = $("mytable td > :input:enabled");

Upvotes: 3

Related Questions