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">
</head>
<body>  
    容器一:
    <div id="container1">
        <img id="image" src="https://openhome.cc/Gossip/images/caterpillar_small.jpg"/>
    </div><br>
    容器二:
    <div id="container2"></div>  
  
<script type="text/javascript">
    document.getElementById('image').onclick = function() {
        let container1 = document.getElementById('container1');
        let container2 = document.getElementById('container2');
        if(this.parentNode === container1) {
            container2.appendChild(this);
        }
        else {
            container1.appendChild(this);
        }
    };
</script>  
</body>
</html>
Output

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

Dismiss x
public
Bin info
JustinSDKpro
0viewers