0

I am trying to recreate sortable jQuery UI behavior with only jQuery:

This is the JSFIDDLE: http://jsfiddle.net/606bs750/48/

Drag and drop works fine, the problem arises when I add new element into parent div.

It appears that mousedown functions aren't getting called on a newly added element.

$('.button').mousedown(function(e) {}); //isn't getting called

Why would that be so and what fix do you recommend?

PravinS
  • 2,640
  • 3
  • 21
  • 25
sanjihan
  • 5,592
  • 11
  • 54
  • 119
  • The `.button` elements are added to the DOM after it loads, so you need to use a delegated event handler: `$('.parent').on('mousedown', '.button'. function(e) { ...`. Also be aware that you're duplicating the `id` attribute every time you append a new button which may cause issues in your JS code. – Rory McCrossan Mar 21 '17 at 10:45
  • adding to ^^^ http://jsfiddle.net/d2g2Lspq/ – Satpal Mar 21 '17 at 10:45

0 Answers0