Monday 15 February 2010

jquery - Update click event of moved DOM element -


I have 2 unordered lists that are in my own div, if I click on a list item in the first list then I want to take it to second place. And on the contrary, double click on the second list.

Code:

  $ ('. Filelist & gt; ul & gt; li & gt; a') Click (function () in the {// file file} Clicked file (list1) // console.log ('file in list'); $ (this) .Parent (). AppendTo ('# queue-list');}); $ ('.quelist & gt; ul & gt; li & gt; a'). Dblclick (function () {// // file clicked in queue (list2 // console.log ('file in queue'); $ (this) .parent () .andTont ('# file-list') ;}};   

The first part works, the list item is moved from 1 list to 2. But when I click (do not double click) in list 2 it is now Also logs in 'File in List', so the onclick function of the transferred element is not updated.

That's because you are handler Therefore, when you change the Thier Dome area, they maintain the same handler that was initially bound.

You can use the ul Elements ( Use the method )

  $ ('.list file & gt; ul'). ('(File in the' list '); $ (this) File clicked on parent () ('doubleClickClick', 'gt; li & gt; a', function () {// // Cli; ('# queue-list');}); $ ( '.quelist & gt; ul') .cked file in qi (list2 // console.log ('file in queue'); $ (This) .parent () appendTo ('#list-list'). });   

On the demo

No comments:

Post a Comment