1

I've tried the code in this thread but it doesn't seem to work for me. I'm using Firefox 15, it works in Chrome.

This is my code :

<!DOCTYPE html>
<head>
  <title>A Simple Draggable Object</title>
</head>
<body>
    <script>
        window.onload=function() {
            var dragItems = document.querySelectorAll('[draggable=true]');

            for (var i = 0; i < dragItems.length; i++) {
                addEvent(dragItems[i], 'dragstart', function (event) {
                    // store the ID of the element, and collect it on the drop later on
                    event.dataTransfer.setData('Text', this.id);
                 });
            }

        };
</script>

    <h1>Test #1: A Simple Draggable Object</h1>
    <div draggable="true">This text should be draggable.</div>
</body>
</html>

Any help is appreciated

Community
  • 1
  • 1
Shishigami
  • 441
  • 3
  • 7
  • 20
  • I bet there's a JavaScript error behind the inactivity. If you install, say, Firebug and watch its JavaScript console as you attempt to move it, do you see an error? – spamguy Sep 14 '12 at 13:26
  • 3
    I've just tried it with FireBug - you have the following error: ReferenceError: addEvent is not defined – Kris C Sep 14 '12 at 13:29
  • Thank's for your help, there's indeed an error there : "ReferenceError: addEvent is not defined" - but why did it work for the people on the other thread? – Shishigami Sep 14 '12 at 13:31
  • 2
    I'm not sure exactly what drag and drop functionality you're looking for, but may be worth looking at a full tutorial e.g. http://www.html5rocks.com/en/tutorials/dnd/basics/ – Kris C Sep 14 '12 at 13:33

1 Answers1

2
window.onload=function() {
        var dragItems = document.querySelectorAll('[draggable=true]');

        for (var i = 0; i < dragItems.length; i++) {
          dragItems[i].addEventListener('dragstart', function (event) {
            event.dataTransfer.setData('Text', this.id);
          });
        }

};

Worked for me. Thanks to Kris C

Community
  • 1
  • 1
Shishigami
  • 441
  • 3
  • 7
  • 20