javascript - Looping in jQuery -
i tring loop loop jquery command 5 times. here code:
for(var = 0; < 5; i++) { $("#droppable_"+i).droppable({ activeclass: 'ui-state-hover', hoverclass: 'ui-state-active', drop: function(event, ui) { $(this).addclass('ui-state-highlight').find('p').html('dropped!'); } }); }
for reason can't work. can me please?
your updated code works fine. remember need set draggable.
working example (using loop) http://jsfiddle.net/t56te/
$("#draggable").draggable(); for(var = 0; < 5; i++) { $("#droppable_"+i).droppable({ activeclass: 'ui-state-hover', hoverclass: 'ui-state-active', drop: function(event, ui) { $(this).addclass('ui-state-highlight').find('p').html('dropped!'); } }); }
html:
<div id="draggable" class="ui-widget-content"> <p>drag me target</p> </div> <div id="droppable_1" class="ui-widget-header"> <p>drop here</p> </div> <div id="droppable_2" class="ui-widget-header"> <p>drop here</p> </div> <div id="droppable_3" class="ui-widget-header"> <p>drop here</p> </div> <div id="droppable_4" class="ui-widget-header"> <p>drop here</p> </div>
Comments
Post a Comment