Here it is my dragstart:
dragstart: function(e) {
$(this).css('opacity', '0.5');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('application/json', {
id: $(this).attr('id'),
header: $('header', this).text()
});
},
I would like to pass some informations such id and text. My drop is:
drop: function(e) {
var data = e.dataTransfer.getData('application/json');
alert(data);
$(this).attr('id', data.id);
$('header', this).text(data.header);
},
But data is undefined, I can't access to my data. Is it the right way?
Thank's!
someone or something that is unpleasant and boring: Waiting in a doctor's office is such a drag!
to draw with force, effort, or difficulty; pull heavily or slowly along; haul; trail: They dragged the carpet out of the house. to search with a drag, grapnel, or the like: They dragged the lake for the body of the missing man. to level and smooth (land) with a drag or harrow.
in drag start
var testjson = {name:"asd",tall:123};
e.dataTransfer.setData("text/plain",JSON.stringify(testjson));
e.dataTransfer.effectAllowed = "copy";
in drop
var data = e.dataTransfer.getData("text/plain");
console.log(JSON.parse(data));
and u will get
Object {name: "asd", tall: 123}
in console.log
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