-2

Looking to add some functionality when users double click on a div to pop up a box. I already have the pop-up functionality which works with inline onClick(). But I would like to change this to double click.

I have tried the following which will work if invoked after an element is added.

$(".dz-preview").dblclick(function() {
    console.log("inside dbl");
    renameFile(this);
});

But I cant seem to figure out how to get it to work on dynamically generated elemenets.

user2524908
  • 861
  • 4
  • 18
  • 46
  • 2
    This is one of many duplicates you may want to look at event delegation. – PSL Oct 10 '13 at 19:00
  • 1
    That obviously won't work because when that is executed the element doesn't exists so the event listener can't be attached, you need to use .on() so it will constantly look for the elements and that – Dvid Silva Oct 10 '13 at 19:05

1 Answers1

7

Try this:

$(document).on('dblclick', '.dz-preview', function() {
    console.log("inside dbl");
    renameFile(this);
});
beercodebeer
  • 990
  • 6
  • 5