Kris Kris - 1 year ago 153
jQuery Question

jQuery Sortable - How to get current dragged element attribue

I am using jqueryui sortable widget. I need to get the current dragged element's data attribues. $(this).data('attribute_name') is not working here. I have also tried some other methods, but not getting the correct result.


<ul class="draggable-item" style="min-height:10px;">
<li data-parent="31" data-id="81" class="ui-state-default">Label</li>
<li data-parent="31" data-id="86" class="ui-state-default">Max Value</li>
<li data-parent="31" data-id="83" class="ui-state-default">Unit</li>
<li data-parent="31" data-id="84" class="ui-state-default">Warning Level High</li>
<li data-parent="31" data-id="85" class="ui-state-default">Warning Level Low</li>


$(document).ready(function() {
start: function( event, ui ) {
//Here i need to get current dragged element's 'parent' attribue.
//console.log(ui.item[0].attributes); - Here i got the entire attribute values in an array. But the order of the array is different in browsers.

Answer Source

Try $(ui.item).data('attribute_name'); or $(event.currentTarget).data('attribute_name');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download