Move one DIV element inside another using jQuery.
Move the following <div id="source"> ... </div> To <div id="destination"> ... </div>
HTML Code :
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Move one DIV element inside another.</title> </head> <body> <div id="nonSelected"> <!--Declaring BUTTON TAGS --> <button id="btnDefault" onclick="moveButton(this)" type="button">Button1</button> <button id="btnPrimary" onclick="moveButton(this)" type="button" >Button2</button> <button id="btnDanger" onclick="moveButton(this)" type="button">Button3</button> </div> <div id="selected"> </div> </body> </html>
CSS Code :
#nonSelected{ position: absolute; top: 10px; left: 10px; width: 180px; height: 180px; background-color: #884333; border-width: 1px; border-style: dotted; border-color: black; padding: 10px; } #selected{ position: absolute; top: 10px; left: 200px; width: 180px; height: 180px; background-color: #498933; border-width: 1px; border-style: dotted; border-color: black; padding: 10px; }
JavaScript Code :
function moveButton(elem){ if( $(elem).parent().attr("id") == "nonSelected" ){ $(elem).detach().appendTo('#selected'); } else{ $(elem).detach().appendTo('#nonSelected'); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code :
CSS Code :
JavaScript Code :