I want to create a binding that captures all click events. And then if the item clicked has a “data-track” attribute do something…
What is the efficient way to do this? Can I bind at the body and let all the events bubble up. Any suggestions on how and how to do this efficiently?
Thanks
You should aim for simplicity over performance: Let jQuery do the work for you, and assume that the jQuery devs are better at optimizing JS than you unless you can prove otherwise.
Use the has attribute jQuery selector to setup a live click handler for all elements with the
data-trackattribute: