JQuery(Javascript)/ CSS,方式重新排列DIV中的元素的顺序,而不使用定位? [英] JQuery (Javascript) / CSS, way to rearrange order of elements within DIV without using positioning?

查看:489
本文介绍了JQuery(Javascript)/ CSS,方式重新排列DIV中的元素的顺序,而不使用定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点不确定如何做到这一点。我有一个主面板,其中我想显示一个DIV基于一个动作。我有在html中这样布局的DIVS:

I'm a bit unsure of how to do this. I have a main panel where I want to display a DIV in that based on an action. I have the DIVS laid out like this in the html:

<div id="container">
   <div id="1"></div>
   <div id="2"></div>
</div>

我不想搞定位,而是想让它发生时, div id = 2以上div id = 1,尽可能简单。

Rather than messing around with positioning, I want to make it so that when something happens I can just put div id=2 above div id=1, as simply as possible. Any advice is appreciated.

推荐答案

在示例中,您可以简单地使用 append <

In the example you are showing you can simply use the append, and prepend jquery methods.

例如,div#1 then div#2 / p>

For example, div#1 then div#2

$('#container').append('#1').append('#2');

重新排序,div#2 then div#1

Reorder, div#2 then div#1

$('#container #2').remove().prependTo('#container');

有很多方法可以写这个。只要记住 prepend 将元素放在容器的开头(第一个元素之前),而 append 在最后一个元素之后。

There are many ways you could write this. Just remember prepend places an element at the beginning (before the first element) of the container, while append places the element after the last element.

这篇关于JQuery(Javascript)/ CSS,方式重新排列DIV中的元素的顺序,而不使用定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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