title: Get dynamic event ID in backbone.js
body: <p>I'm messing around with backbone.js for the first time and am also new to MVC.. </p>
  
  <p>This sample code creates a list and each list has an anchor with the class of <em>updateTotal</em> . I can successfully call the <em>updateVar</em> function using the <strong>click a.updateTotal':'updateVar'</strong> event</p>
  
  <p>My question is how can I get the <strong>ID</strong> of the clicked anchor? Typically in jQuery I have used something like $(this).attr("id"); to get the ID of the clicked element.</p>
  
  <p>Thanks!</p>
  
  <p><em>My code....</em></p>
  
  <pre><code>(function($){
     var Item = Backbone.Model.extend({
      defaults: {
       itemName: 'Item Name',
       itemCount: 0 
     }
  });
  
  var List = Backbone.Collection.extend({
   model: Item
  });
  
  
  
  var ListView = Backbone.View.extend({    
  
    el: $('body'), // attaches `this.el` to an existing element.
  
    events: {
      'click button#addItem': 'addItem',
      'click a.updateTotal':'updateVar'
    },
  
    initialize: function(){
      _.bindAll(this, 'render', 'addItem', 'appendItem', 'updateVar');
  
      this.collection = new List();
      this.collection.bind('add',this.appendItem);
      this.collection.bind('updateVar',this.updateVar);
  
      this.counter=0; //total added so far
      this.render();
    },
  
    render: function(){
      $(this.el).append('&lt;button id="addItem"&gt;Add item&lt;/button&gt;');
      $(this.el).append('&lt;ul&gt;&lt;/ul&gt;');
      _(this.collection.models).each(function(item){
       appendItem(item);
      }, this);
    },
  
    addItem: function(){
      this.counter++;
      var item = new Item();
      item.set({
        itemName: 'Item '+this.counter,
        itemID: 'item'+this.counter
      });
    this.collection.add(item);
    },
  
    appendItem: function(item){
      $('ul', this.el).append("&lt;li&gt;"+item.get('itemName')+" (&lt;span id=\""+item.get('itemID')+"-counter\"&gt;"+item.get('itemCount')+"&lt;/span&gt;) &lt;a class=\"updateTotal\" id=\"update-"+item.get('itemID')+"\"&gt;[update]&lt;/a&gt;&lt;/li&gt;");
    },
  
    updateVar: function(){
       //------------------------------------
       //I want to get the ID to use here
       //------------------------------------
    }
  
  });
  
   // **listView instance**: Instantiate main app view.
   var listView = new ListView();      
  })(jQuery);
  </code></pre>