Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Move Dynamically Appended DIV</title>
<script src="http://threedubmedia.com/inc/js/jquery-1.7.2.js"></script>
<script src="http://threedubmedia.com/inc/js/jquery.event.drag-2.2.js"></script>
<script src="http://threedubmedia.com/inc/js/jquery.event.drag.live-2.2.js"></script>
</head>
<body>
    <button id="divgen">Gen Div</button>
    <div class="container">
        <div class="drag" style="left:20px;"></div>
        <div class="drag" style="left:100px;"></div>
        <div class="drag" style="left:180px;"></div>
    </div>
</body>
</html>
 
.drag {
    position: absolute;
    border: 1px solid #89B;
    background: #BCE;
    height: 58px;
    width: 58px;
    cursor: move;
    top: 120px;
}
 
jQuery(function($){
    $('.drag').drag(function( ev, dd ){
        $( this ).css({
            top: dd.offsetY,
            left: dd.offsetX
        });
    });
  
    $("#divgen").click(function() {
        $("div.container").append('<div id="whatever" class="drag">my div</div>');
    });
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers