Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Create a webpage and implement the dragable feature to drag an object wherever the user wants.
Apply the following constraints:

tag with id as draggable
tag with the image provided, assume the image is in the same directory with the name "fish.jpg"

tag with the text "Drag me around"
Use the following JQuery Libraries:

https://code.jquery.com/jquery-1.10.2.js
https://code.jquery.com/ui/1.10.2/jquery-ui.js

What I have tried:

<!DOCTYPE HTML>
<html>
    <head>
        <script>
            function allowDrop(ev)
            {
                ev.preventDefault();
            }
            function drag(ev)
            {
                ev.dataTransfer.setData("text",ev.target.id);
            }
            function drop(ev)
            {
                ev.preventDefault();
                var data=ev.dataTransfer.getData("text");
                ev.target.appendChild(document.getElementById(data));
            }
        </script>
    </head>
    <body>
        <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
        <img id="drag1" src="fish.jpg" draggable="true"
        ondragstart="drag(event)">
        <p>Drag me around</p>
    </body>
</html>
Posted
Updated 10-Sep-18 3:23am

1 solution

You are looking at the wrong place, what you have tried was based on HTML5 drag and drop API, since you are supposed to use jquery ui, the correct reference is here: Draggable | jQuery UI[^] and the jquery libraries are way too old.
It's really a bad ideas to skip lessons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900