troubleshooting Question

drag elements

Avatar of codelevel
codelevel asked on
JavaScriptjQueryWeb Languages and Standards
6 Comments1 Solution86 ViewsLast Modified:
i want to drag and drop the elements based on the class.
please help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<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 style="float:left;width:200px;border:1px solid blue;margin:0 0 20px 0"> 
<img src="" alt="1" class="male" draggable="true" ondragstart="drag(event)"/>
<img src="" alt="2" class="male" draggable="true" ondragstart="drag(event)" /> 
<img src="" alt="3" class="female" draggable="true" ondragstart="drag(event)"/> 
<img src="" alt="4" class="female" draggable="true" ondragstart="drag(event)" /> 
<img src="" alt="5" class="male" draggable="true" ondragstart="drag(event)" /> 
<img src="" alt="6" class="female" draggable="true" ondragstart="drag(event)"/> 
</div>
<div style="float:left;width:200px;border:1px solid blue;margin:0 10px 0 0;clear:both" ondrop="drop(event)" ondragover="allowDrop(event)">
  <p>female</p>
</div>
<div style="float:left;width:200px;border:1px solid red" ondrop="drop(event)" ondragover="allowDrop(event)">
  <p>male</p>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros