3

I'm using jQuery along with the jQuery validation plug-in.

I have a table where each column after the first column contains a form field such as a checkbox, a text field, etc. I use <th> for headers, so only <tr> elements have form fields.

How do I select all rows whose entire form fields are empty? By empty, I'm talking about a text field with an undefined value, a checkbox unchecked, a select field with nothing selected, etc. I'm not supposed to select a row if it has at least one non-empty form field.

Is this possible? Can someone please shed some light on this?

1 Answer 1

4

This shouldn't be too difficult using .filter():

$('tr').filter(function(){
    return !$(this).find('input:text:not(:empty), textarea:not(:empty), input:checked, option:selected').length;
});

This searches the tr to find

  • non-empty text inputs
  • non-empty textareas
  • checked checkboxes/radio boxes
  • selected option elements

and returns false if any are found (i.e. removes them from the selection).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.