1

I am selecting a list of table rows within my document.

The following code selects:

  1. All table rows...
  2. That contain a DIV with class .val-string
  3. With a child input that holds the value "null".

$('tr').children('.val-string').children('input'):not([value!=null])').each(function(k,v) { });

This works for selecting those inputs that contain the value "null", but I also want it to work with "Null", "NULL" or even "nUlL".

I have tried using:

... children('input'):not([value.toLowerCase()!=null])') ...

amongst other variations/placements of the toLowerCase() function.

Basically, can what I ask for be performed in one line of code like the one I'm trying to execute above?

This link seems to suggest using a modified :contains function, but I don't want to change this function for all my code as it is used elsewhere and requires case sensitivity.

Community
  • 1
  • 1
Jimbo
  • 25,790
  • 15
  • 86
  • 131

1 Answers1

3

there is no selector for or but you can use filter

$('tr .val-string input').filter(function(){  
    return this.value.toLowerCase() =='null';
}).doSomething();
charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • This is perfect! I doubt an edit request would go through, so could you change .doSomething() to .each(function(key,value) { // Do something with $(this) }); for the final answer in case anyone else comes along? Thanks very much! – Jimbo Jan 15 '13 at 12:17
  • really irrelevant.. `doSomething()` can be any jQuery method including `each` and chances are you don't even need to use `each`... what are you wanting to do with them? – charlietfl Jan 15 '13 at 12:18
  • No worries - hide each of the matched rows using $(this).parent().parent().hide() :) [IF another attr within that tr is 'highlighted' for example] – Jimbo Jan 15 '13 at 12:25
  • Don't need each for that... just change `doSomething` to `closest('tr').hide()`. Will affect all matching rows with those input tags – charlietfl Jan 15 '13 at 12:30
  • Yep, `closest('tr').hide()` does away with having `.parent().parent()`. Thanks for simplifying my code and teaching me in the process - much appreciated! – Jimbo Jan 15 '13 at 12:37