I'm using jQuery's .on()
with a selector to delegate to a filtered set of descendants, like this:
selectedElement.on("click", "[data-click]", clickHandler);
In this case, binding the clickHandler function to a click event on any descendant that has a "data-click" attribute (with any value).
If selectedElement
itself has a "data-click" attribute, it is not bound. I can't use the selected element's parent instead, because it contains other children that I don't want bound. This bind is occurring inside a function that receives selectedElement
as an argument, so I have no advance knowledge of what kind of element it is or what selector I would use to select it. I would prefer not to have to bind the selected element separately.
Is there a way to include the selected element itself in the set which is filtered and bound by .on
?