Peter Ehrlich
Peter Ehrlich

Reputation: 7135

jQuery exclude selector matches from #find results

How best would I exclude results from #other_section, given a structure like this?

<form>
  <input id=one>
  <div id=other_section>
    <input id=two>
  </div>
</form>

Here's a possible API:

inputs = @find(":input").exclude("#other_section :input")

Upvotes: 0

Views: 677

Answers (2)

gooogenot
gooogenot

Reputation: 509

$(':input:not(#other_section > :input)');

example: http://jsfiddle.net/5XCcF/

Upvotes: 2

Peter Ehrlich
Peter Ehrlich

Reputation: 7135

Here's my solution:

$.fn.exclude = (selector)->
  excluded_items = @end().find(selector)
  @filter ->
    !_.include(excluded_items, this)

Upvotes: 0

Related Questions