Frage

Stack.

I'm using Backbone's event map in my View.

JS:

events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    // Get the value of the button clicked
    e.preventDefault();
    $(".edit-info-button").click(function(){parseEdits(this.value);});
}

HTML:

<button class="button edit-info-button" value="edit address">EDIT</button>

When edit-info-button is a class, the event listener does not work. pullEdits() never fires.

When I change edit-info-button into an id ("click #edit-info-button", "button id='edit-info-button', etc.) pullEdit() and all functions after it run successfully.

The issue is, the page I'm working on needs multiple edit buttons and I'd like to give them the same class and pull the value instead of giving them all unique ids.

Am I missing something? Thanks.

War es hilfreich?

Lösung

Try this instead.

...
events: {
    "click .edit-info-button": "pullEdits"
},
pullEdits: function(e){
    var val = $(e.target).attr('value')
    return parseEdits( val );
}
...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top