Search code examples
javascriptbackbone.jsbackbone-stickit

Backbone, Getting the id/name of the of changed element


I am using Backbone.js with stickit for binding. I have something like below. How do I know which element the user has clicked? (Radio buttons)

initialize: function() {
  this.listenTo(this.model, 'change', this.blockDiv);
}
blockDiv : function() {
  console.log('The changed element is '+); //How do i know which element the user has changed?
}
bindings : {
  '[name=element1]' : element1,
  '[name=element2]' : element2
}

Solution

  • You are listening changes from your model, not DOM events directly. You can check what attributes of model have changed with changedAttributes.