2014-05-23 53 views
0

目前,我設置了我的頁面,當我點擊一個div時,彈出的子菜單彈出出現在我點擊的div下面。我試圖分離()子菜單和insertAfter()和空白左或浮動,以便它出現在div被點擊的右側。HTML/jQuery detach()然後insertAfter()元素

* Here is a picture Example of what I currently have and what I am trying to do

HTML:

<div> 
    <div class="nav-name nav-padding">Alpha</div> 
     <div class="Beta"> 
      <div class="Delta"> 
       <div class="Omega">A</div> 
       <div class="Omega">B</div> 
       <div class="Omega">C</div> 
       <div class="Omega">D</div> 
      </div> 
     </div> 
    <div class="foo" style="display: none;"></div> 
</div> 

腳本:

function ClickItem() { 
    $('.nav-name').click(function() { 
     var itemText = $(this); 
     $(this).next('.delta').slideToggle('slow'); 
     //$(this).next('.delta').toggle('slow'); 
     //itemText.next().html().detach(); 
     //itemText.next().html().insertAfter(.nav-name).css("margin-left", "20px"); 

    }); 
} 

我不知道這是否是最好的方法,如果我應該努力使這項工作。如果有更好的方法,請隨時推薦一種不同的方法來完成我的任務。

謝謝

+1

.html()返回一個字符串,字符串沒有detach方法。我不認爲你需要.html() –

+2

你不能簡單地使用** css **來定位子菜單..?!! –

+1

另外,.next不會執行您認爲的操作。 –

回答

0

從阿爾法分離和插入後Alhpa 做這樣的(check the link):

var beta = $('.Beta'); 
    var cloned = beta.clone(); 
    beta.hide(); 
    beta.remove(); 
    cloned.addClass('float_left'); 
    $(cloned).insertAfter('#alp'); 

我已經添加了ID ALP到你的阿爾法股利。

但仍然CSS會是一個更好的解決方案!