I’m using Backbonejs routing and trying to get the element that triggered a route, for example if I have:
<a href="#/files" id="link123">Click</a>, is there anyway inside of a route to know which element was clicked so I can get the id or class any arbitrary attribute of that element?
Thanks!
First off, from the official Backbone documentation:
I would recommend following that pattern
Secondly to solve your problem, what you can do is in your view, bind to the ‘click’ event of your links as such:
where
what this does now, is that you’ve intercepted in your view, the element that you use to trigger the
onClickmethod.If you would provide a bit more information as to what exactly you’re trying to achieve, perhaps I can elaborate my answer more.