DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

Backbone.js click event not triggered

View:

 Member.Views.Popover = Backbone.View.extend({
    template: "member/default",
    tagName: 'a',
    className: 'header-auth member',
    events: {
      'click a.member': 'toggle'
    },        
    initialize: function() {    
      //todo
    },
    toggle: function(){   
      console.log("toggle");
    }
  });

Output:

<a class="header-auth member">
    //content from template
</a>

First problem: first I defined just a template without tagName and className because this data was already set in the template. But this wrapped the template with a div. To avoid that I set tagName and className and removed this data from template because now it is set by backbone.

Second problem: now that I use tagName the click event does not work anymore.

Any ideas how to fix this?

Upvotes: 0

Views: 243

Answers (1)

kalley
kalley

Reputation: 18462

You can should change click a.member to merely click, since the element is your view.

Upvotes: 2

Related Questions