This code should make an element disappear from a list when it is dropped on another element (called cookiemonster)
addEvent(cookiemonster, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation();
var el = document.getElementById(e.dataTransfer.getData('text'));
el.parentNode.removeChild(el);
return false;
});
This code should make an element disappear from a list when it is dropped on another element (called cookiemonster)
addEvent(cookiemonster, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation();
var el = document.getElementById(e.dataTransfer.getData('text'));
el.parentNode.removeChild(el);
return false;
});
Share
Improve this question
edited Mar 26, 2014 at 23:43
Kara
6,22616 gold badges53 silver badges58 bronze badges
asked Aug 23, 2013 at 16:13
KepedizerKepedizer
8562 gold badges10 silver badges25 bronze badges
3
-
1
This means that
el
is null.... – Naftali Commented Aug 23, 2013 at 16:14 -
what is the output of
e.dataTransfer.getData('text')
? there seems to be no element by that ID – Harry Commented Aug 23, 2013 at 16:14 -
It seems there is no element returned by the
document.getElementById()
; what doese.dataTransfer.getData('text')
return? Does it match anid
of an element in the document? – David Thomas Commented Aug 23, 2013 at 16:15
1 Answer
Reset to default 1create an auxiliar variable like this
addEvent(cookiemonster, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation();
var el = document.getElementById(e.dataTransfer.getData('text'));
var aux = el.parentNode;
aux.removeChild(el);
return false;
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744613021a4583879.html
评论列表(0条)