javascript - How to get which div/ui.helper clicked in drag event jqueryui/jquery? -
on jquery ui's site:
http://jqueryui.com/demos/draggable/
if have:
<div id="someid" class="someclass">he</div> <div id="otherid" class="otherclass">he2</div>
and:
$('#someid','#otherid').draggable({ drag: function(event, ui) { alert(ui.helper.theidoftheclickeditem); // goes here? } });
how id or class of id using "ui" variable callback? if not possible, how "event" variable?
you want:
$("#someid, #otherid").draggable({ drag: function(event, ui) { console.log(ui.helper[0].id); } });
(or use ui.helper.attr("id")
)
note: ui.helper
jquery object, why must either use .attr("...")
retrieve id
or access matched element @ index 0 , directly id.
or without using ui
argument (probably i'd recommend):
$("#someid, #otherid").draggable({ drag: function(event, ui) { console.log(this.id); // "this" dom element being dragged. } });
here's working example: http://jsfiddle.net/andrewwhitaker/lkcsx/
Comments
Post a Comment