Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js accessing elements which fired a View's event [duplicate]

I need to access some information about the element that was bound to a Backbone View's events (i.e. the href="something"). How do I access this object?

var SomeView = Backbone.View.extend({

    events: {
        "click a.some-class": "doStuff"
    }

    doStuff: function(e) {
        e.preventDefault(); // prevent default behavior
        // How can I access the element (i.e. a <a>) here?
    }

});
like image 801
dlrust Avatar asked Dec 09 '22 06:12

dlrust


1 Answers

$(e.target) will work.

doStuff: function(e) {
   e.preventDefault();

   $(e.target).css('color', 'red');

 }

See http://jsfiddle.net/aD3Mn/2/

like image 113
Sam Dolan Avatar answered Apr 30 '23 04:04

Sam Dolan