javascript - How to move div element inside another div element? -


var $selected = $();    var $itemlv1 = $("#create-summary .lv1");     $itemlv1.click(function(){        $selected = $(this);        $(this).toggleclass('clicked').siblings().removeclass('clicked');    });      $("#moveup").click(function(){        $selected.add($selected.nextuntil(":not(.lv2)"))                        .insertbefore($selected.prevall(".lv1:first"));    });      $("#movedown").click(function(){      $selected.add($selected.nextuntil(":not(.lv2"))               .insertafter($selected.nextall(".lv1:first"));    });
.clicked{    color: red;    font-weight:700;  }    .lv2, .lv3 {    margin-left:15px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <div id="create-summary">              <div class="lv1"> introduction</div>              <div class="lv1">1. aaa</div>              <div class="lv1">2. bbb</div>              <div class="lv1">3. ccc                <div class="lv2">3.1 aaa</div>                <div class="lv2">3.2 bbb</div>                <div class="lv2">3.3 ccc</div>                <div class="lv2">3.4 ddd                  <div class="lv3">3.4.1 xxxxx</div>                  <div class="lv3">3.4.2 yyyyy</div>                  <div class="lv3">3.4.3 zzzzz</div>                </div>              </div>              <div class="lv1">4. ddd</div>              <div class="lv1">5. eee</div>          </div>    <button type="button" id="moveup">up </button> /   <button type="button" id="movedown">down</button>

now, can move or down lv1 element child element.

however, how move div element inside child div?(only in lv3 or lv4 lv5 or lv6)

fir example, want move "ccc" in lv2 or move xxxxx in lv3. there way can that?

i assume want functionality this,

var $selected = $(); var $itemlv1 = $("#create-summary [class^=lv]");  $itemlv1.click(function (e) {     $selected = $(this);     var x = $(this).toggleclass('clicked');     $("[class^=lv]").not(x).removeclass("clicked child").addclass("child");     x.siblings().removeclass('clicked');     e.stoppropagation(); });  $("#moveup").click(function () {     $selected.insertbefore($selected.prev("[class^=lv]")); });  $("#movedown").click(function () {     $selected.insertafter($selected.next("[class^=lv]")); }); 

demo


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -