I am using sortable widgets from the jQuery UI library and noticed something. If I sort/drop a draggable item like a div containing a script like alert(‘run once’). It will execute the javascript code every time it gets dropped. I understand that this pretty much makes sense since it writes it to the DOM each time. But now i’m wondering if anyone knows a way around this. The div’s (portlets) i tend to sort all contain javascript which shouldn’t be run more than once 🙂
Thanks.
Adding a class to the item when it is dropped and checking for that class on subsequent drops should work. Something like: