QUESTION:
I am trying to use JQuery's .find()
to find all descendants within an element at any level that have a given attribute, but not the descendants of those descendants with the same attribute.
TO HELP UNDERSTANDING:
JQuery
The intended goal of the query below is find all descendants within element $("#some_id")
(at any level) that have some_attribute
attribute, but not the descendants of those descendants with the same attribute.
$("#some_id").find("[some_attribute]");
HTML
<span id="some_id" some_attribute>
<span some_attribute> <!-- SELECT -->
<span some_attribute> <!-- IGNORE -->
<span some_attribute> <!-- IGNORE -->
</span>
</span>
<span>
</span>
</span>
<span>
<span some_attribute> <!-- SELECT -->
<span>
<span some_attribute> <!-- IGNORE -->
</span>
</span>
<span some_attribute> <!-- IGNORE -->
</span>
</span>
</span>
<span>
<span>
<span>
<span some_attribute> <!-- SELECT -->
</span>
</span>
</span>
</span>
</span>
NOTE: I need a generic approach... I explain better! Suppose I don't know the selector $("#some_id")
I only have the result of that query. Also consider that this result may refer to an element that may be within another element with the some_attribute
attribute.