Say I have this HTML:
<div id="knownid">
<div class="foo">
<ul>
<li><a><span custom-attr="custom attribute 1"></span></a></li>
<li><a><span custom-attr="custom attribute 2"></span></a></li>
<li><a><span custom-attr="custom attribute 3"></span></a></li>
</ul>
</div>
</div>
My issue is that in order to create a click event for the a > span elements, with the custom-attr attribute, I'd normally do:
$('span[custom-attr]').on('click', function(e){
// ...
});
However, that would create an event on EVERY element with that attribute name, but how would I make it so that it would only create a click event if it's a child of the knownid ID?
$('div[id="knownid"] > div > ul > li > a > span').on('click', function(e){
// ...
});
I'd like to avoid this long selector.