I would like to select only one class from severals with the condition that the selected class has any div-descendant with the id "#exampleId".
I thought something like this could work, but it didn’t:
$(".myClass").has(div).attr("id","#exampleId").
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:
myString.replace('#','');
Thanks in advance
You could just pass the ID in the selector for
has(). No need to remove the#either.Or even do it in one selector: