How can I filter out a subtree and then search in jQuery?

http://stackoverflow.com/q/27514482/1430996

by Jeromy French

HTML

<div id='unknown' class='ted-panel'>
  <div class='ted-collapse'>Use `:first-child` to make me green</div>

  <div class='ted-panel'>
    <div class='ted-collapse'>But not me!</div>
    <div class='ted-collapse'>&hellip;or me!</div>
    <div class='ted-collapse'>&hellip;or me!</div>
  </div>
</div>
<div id='test' class='ted-panel'>
  <div class='ted-collapse'>Use #test to make me green!</div>

  <div class='ted-panel'>
    <div class='ted-collapse'>But not me!</div>
    <div class='ted-collapse'>&hellip;or me!</div>
    <div class='ted-collapse'>&hellip;or me!</div>
  </div>
</div>

JavaScript

$('div.ted-panel:first-child').find('.ted-collapse:not(div.ted-panel:first-child > .ted-panel .ted-collapse)').css('color', 'green');
$('#test').find('.ted-collapse:not(#test > .ted-panel .ted-collapse)').css('color', 'green');