This is working:
$(".my_dragging_class").each( makeDraggable($(this).get()[0]) );
var makeDraggable = function (el){
el.draggable = 'true';
el.addEventListener('dragstart', function(e){
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', 'test');
console.log('dragstart');
},
false);
}
This is NOT working:
$(".my_dragging_class").makeDraggable();
$.fn.makeDraggable(){
$(this).attr('draggable','true');
$(this).bind('dragstart', function(e){
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', 'test');
console.log('dragstart');
},
false);
}
Error message: I receive a 'e.dataTransfer is undefined' for the line e.dataTransfer.effectAllowed = 'move';
. My Browser is FireFox 10.0.2
Is it possible to use dataTransfer with jQuery this way?
Try:
$.fn.makeDraggable(){
$(this).attr('draggable','true');
$(this).bind('dragstart', function(e){
e.originalEvent.dataTransfer.effectAllowed = 'move';
e.originalEvent.dataTransfer.setData('text/html', 'test');
console.log('dragstart');
},
false);
}
The jQuery event object does not have a dataTransfer
property.
The jQuery event object does not have a dataTransfer property... true, but one can try:
jQuery.event.props.push('dataTransfer');
kr, zara
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With