I would like to select only one class from severals with the condition that the selected class has any div-descendant with the id
I thought something like this could work, but it didn't:
The second problem: I have to get rid first of the hash "#". because the String (#exampleId) has been generated dynamically... It looks something like this:
var myString = "#exampleId"
And the following approach didn't work:
Thanks in advance
You could just pass the ID in the selector for
has(). No need to remove the
Or even do it in one selector:
You already accepted an answer, but I'll throw this one out there anyway.
If you have more than a few
.myClass elements on the page, it would probably be more efficient to select the
#exampleId first, then traverse up to the first
Or if the ID was in a variable, do this:
var myString = "#exampleId";
These will give you the first parent of the
#exampleId that has
You could use
.closest('.myClass') if you want as well.