I would like some help to improve the following. How can I get a an incorrect dropped answer to be shown in red or green if it is correct. This is gap filling Drag & Drop exercise for my language students.
Below is the simple code I am using:
<!DOCTYPE HTML>
<html>
<head>
<style>
.draggable {
width: 120px;
padding: 1px;
border: 1px solid gray;
margin: 0px;
text-align:center;
}
#div1,#div2
{display:inline-block;min-width:150px;min-height:10px;
border-style:solid;border-width:0px;border-bottom-width:2px;}
</style>
<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.parentNode.replaceChild(document.getElementById(data), ev.target);
document.getElementById(data).className = "";
}
</script>
</head>
<body>
<span class="draggable" id="drag1" draggable="true" ondragstart="drag(event)">
HEART TO HEART</span>
<span class="draggable" id="drag2" draggable="true" ondragstart="drag(event)">
EYE TO EYE</span>
<br />
<ol>
<li>Our relationship was going badly wrong, but after we sat down and had a
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div> talk we
decided to try again. We're a lot happier now.
</l7>
<li>I wish my wife and my sister could agree about some things. The problem is that
they just can't see <div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)">
</div> and argue about everything.
</li>
</ol>
</body>
</html>
` exists for a reason...
– Mr. Polywhirl Jun 18 '14 at 18:33