title: How can I select the set of all nodes S which terminate a path from node A of class 'X' in which only the root and terminal node are of class 'X'?
body: <p>Basically I'm looking for a way to select child "my-class" nodes even if they aren't directly children, and to not select any grandchildren "my-class" nodes given any "my-class" element.
  For example, given "a" it would return "b", "g". given "b" it would return "c", "f", given "c" would return "d", "e", and "d" would return nothing. I can't seem to find a way to do this without traversing the DOM.</p>
  
  <pre><code>&lt;div class="my-class" id="a"&gt;
    &lt;div&gt;
      &lt;div class = "my-class" id="b"&gt;
        &lt;div class = "my-class" id="c"&gt;
          &lt;div class = "my-class" id="d"&gt;
          &lt;/div&gt;
          &lt;div class = "my-class" id="e"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class = "my-class" id="f"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div&gt;
        &lt;div class = "my-class" id="g"&gt;
          &lt;div&gt;
            &lt;div&gt;
              &lt;div class="my-class" id="h"&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>What I'm doing now is just traversing the DOM. If its "my-class" perform my operation, and if its not continue traversing down that part of the tree.</p>
  
  <pre><code>function traverse(element) {
    $(element).children(".my-class").trigger("my-event");
    var children = $(element).children(":not(.my-class)");
    for (var i = 0; i &lt; children.length; i++) {
      traverse(children[i]);
    }
  }
  </code></pre>