jquery将元素移动到最后的子位置 [英] jquery move element to last child position

查看:594
本文介绍了jquery将元素移动到最后的子位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含一些随机元素的< div> ,但是有一个元素是我用这个唯一的选择器创建的: $( 'myUniqueElement')。我希望使用 .insertAfter()将此元素移动到我的< div> 中的最后一个子元素位置可能吗?什么是解决方案?



这是我的解决方案: http://jsfiddle.net/silverlight/RmB5K/3/ 这是行吗??



HTML:

 < div class ='p'> 
< div class ='myUniqueElement'>唯一< / div>
< div>项目< / div>
< div>项目< / div>
< div>项目< / div>
< / div>
< input type ='button'id ='b'value ='Do'/>

Javascript:

 < $('。')。$('。')$('。')。$('#b')。on('click',function(){
$('。myUniqueElement')。insertAfter($('。p:last-child'))
});

CSS:

  .myUniqueElement {color:red;} 


解决方案

尝试

  var mydiv = $('my-div-selector'); 
mydiv.find('。myUniqueElement')。appendTo(mydiv)

或简单的

  $('my-div')。append($('。myUniqueElement'))


Let's say I have a <div> that contains some random elements, but there is one element I've created with this unique selector : $('.myUniqueElement'). I want to use .insertAfter() to move this element at last child position in my <div> is that possible ? what is the solution ?

This is my solution: http://jsfiddle.net/silverlight/RmB5K/3/ is this OK ??

HTML:

<div class='p'>
    <div class='myUniqueElement'>unique</div>
    <div>item</div>
    <div>item</div>
    <div>item</div>
</div>
<input type='button' id='b' value='Do'/>

Javascript:

$('#b').on('click',function(){
    $('.myUniqueElement').insertAfter($('.p :last-child'))
});

CSS:

.myUniqueElement{color:red;}

解决方案

Try

var mydiv = $('my-div-selector');
mydiv.find('.myUniqueElement').appendTo(mydiv)

or simple

$('my-div').append($('.myUniqueElement'))

这篇关于jquery将元素移动到最后的子位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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