为什么不jQuery的附加工作HTML列表项的结束? [英] Why doesn't jQuery Append work for the end of HTML List Items?

查看:135
本文介绍了为什么不jQuery的附加工作HTML列表项的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想克隆一个列表项,然后将其追加到克隆的列表项的底部,注意它应该是下面的列表项被克隆,而不是因为我能做到这一点的列表的底部我。的目的是为了与jQuery.ui排序使用它。

I'm trying to clone a list item, and then append it to the bottom of that cloned list item, note that it should be below the list item being cloned, not at the bottom of the list as I can do that myself. The purpose is to use it with jQuery.ui sortable.

一切工作正常,其实我甚至可以克隆和附加权利。然而,追加它的之前结束&LT; /李&GT; 标记,并为我的生活,我不能强迫它追加< b>在此标记。

Everything is working fine, in fact I can even get the cloning and the appending right. However, it appends it before the closing </li> tag, and for the life of me I can't force it to append after this tag.

这是HTML标记:

<ul id="column-2" class="connectedSortable">
    <li class="ui-state-default">
    	<div class="label">feature</div>
    	<div class="action">
    		<div class="delete"></div>
    		<div class="other"></div>
    	</div>
    </li>
</ul>

我们关心的部分是类=其他这在被点击将复制列表项。

The part we're concerned with is class="other" which upon being clicked on will duplicate the list item.

这是jQuery的迄今:

This is the jQuery so far:

// This works fine
$(".other").click(function() {

    // This needs to be set (global) to be used later on in some future code.
    actionTarget = this; 		

    // This grabs the whole list item
    var targetStory = $(actionTarget).parent().parent();

    // This clones the list item, as well as appending 
    // that clone to the cloned list item
    $(targetStory).clone().appendTo(targetStory);

})

这工作得很好,它抓住列表项,克隆它,然后转储在屏幕上 - 但在错误的地方:(

This works well, it grabs the list item, clones it, then dumps it on the screen - but in the wrong place :(

<ul id="column-2" class="connectedSortable">
    <li class="ui-state-default">
    	<div class="label">feature</div>
    	<div class="action">
    		<div class="delete"></div>
    		<div class="other"></div>
    	</div>
    	<li class="ui-state-default">
       		<div class="label">feature</div>
       		<div class="action">
       			<div class="delete"></div>
       			<div class="other"></div>
       		</div>
    	</li>
    </li>
</ul>

任何人有,为什么它不附加到列表项的末尾任何想法被克隆,以及如何解决这个问题?

Anyone have any idea why it's not appending to the end of the list item being cloned, and how to resolve this?

推荐答案

也许你想使用而不是appendTo

perhaps you want to use after instead of appendTo

这篇关于为什么不jQuery的附加工作HTML列表项的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆