0

I want to capture double click event in Backbone view

var HomePage = Backbone.View.extend({
     initialize: function(){
        this.render();
     },
     render: function(){
        var template = _.template($('#app1').html());
        this.$el.html(template);
     },
     events: {
        'click #btn1': function(){
            alert('Single Click');
        },
        'dblclick #btn1': function(){
           alert('Double click');
        }
     } 
});

var view1 = new HomePage({
    el: '#container'
});

Double click does not work in backbone. How do we capture it?

Similar to

$('#btn1').on('dblclick', function(){
    alert('Double click');
});
user544079
  • 16,109
  • 42
  • 115
  • 171

1 Answers1

0

The issue here is that your alert is firing after a single click and halting execution. Changing your alerts to console.logs will show that both events are firing as expected:

events: {
    'click #btn1': function() {
        console.log('single click');
    },
    'dblclick #btn1': function() {
       console.log('double click');
    }
 }

http://jsfiddle.net/rvLgybom/

You will then likely run into the issue of both single and double clicks firing. This is discussed further here: Backbone.js - Both click and double click event getting fired on an element

Community
  • 1
  • 1
lucasjackson
  • 1,515
  • 1
  • 11
  • 21