2

Observe:

enter image description here

There are 275 elements on my page, of which 30 are inputs. 12 of the inputs are descendants of tr.items elements and consequently there are 18 inputs, which are not. How can I select the latter?

As you can see $(:not(tr.items) input) selects all the inputs.

mark
  • 59,016
  • 79
  • 296
  • 580
  • Indeed, I must have missed that one - voted to close. – mark Sep 04 '12 at 00:27
  • I see my answer is derivative from that question's accepted answer as well. I cannot claim originality as I've seen the `:not` selector being applied for these situations countless of times. However, closing a question which has an accepted answer doesn't do much besides adding an ugly banner to it, so I'll save my close votes for where it's more needed. `=]` – Fabrício Matté Sep 04 '12 at 00:37
  • Does one have a quota on the close votes? – mark Sep 04 '12 at 01:26

4 Answers4

6
$('input:not(tr.items input)')

Fiddle

My selector matches all inputs which do not match tr.items input. Simply put, it selects all inputs which aren't descendant of tr.items.

:not(selector) Reference

Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
2

Try this.

$('input').filter(function(){
   return $(this).closest('tr.items').length === 0
})
Ram
  • 143,282
  • 16
  • 168
  • 197
0

Try:

var notwanted = $('tr.items').find('input');

var wanted =  $('input').not(notwanted);
sajawikio
  • 1,516
  • 7
  • 12
0
var textinputs=$('input:text').map(function(){
   if($(this).parents('tr.items').length == 0){
    return $(this);
   } else {
    return null;
   }
 })

This will return an array-like object of those elements. You could also use $.each;

dgo
  • 3,877
  • 5
  • 34
  • 47