javascriptbackbone.jsbackbone-events

Javascript event object: Where is the selector


I have following setup in my Backbone View:

var SomeView;

SomeView = Backbone.View.extend({
    initialize: function() { this.render(); },
    render: function() { // render form },
    events: {
        "keydown form.registration input": "checkInput"
    },
    checkInput: function(e) {
        console.log(e);
        // this doesn't work but I am searching for such a function
        var attr = e.getAttributeWhichTriggeredEvent;
        $(attr).val();
        // validate...
    } 
});

As you see, I would like to get the selector of the element which triggered the event, so that I can, for example, use the input value.

As I looked through the console in Chromium, I found some (current) target attributes in the event object. Unfortunatly they don't contain anything which I could use to identicate the element but maybe I just not looked enough..

So how do I do this?


Solution

  • I think you want..

    $(e.target).val()