Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body contenteditable="true">
    <p> first paragraph </p>
    <p> second paragraph
      <span class="father">
        <img id="first-child" src="http://www.telegraph.co.uk/content/dam/Travel/Destinations/Africa/Mauritius/Mauritius---Beaches---Tropical-beach-large.jpg" width="200" height="auto">
        <span id="second-child" style="color:red;">Text</span>
      </span>
    </p>
</body>
</html>
 
var span; var clone; var id;
window.onload = function(){
    id = document.getElementsByClassName('father')[0];
    var b = document.body;
    id.addEventListener("dragstart", dragStart, false);
    id.addEventListener("dragend", dragEnd, false);
    b.addEventListener('drop', function(event){dropp(event)}, false);
}
function dragStart(){
    span = document.getElementsByClassName('father')[0];
    clone = span.cloneNode(true);
}
function dragEnd(){
    if(document.getSelection){
        range = window.getSelection().getRangeAt(0);
        range.insertNode(clone);
    }
}
function dropp(e){
    e.preventDefault();
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers