是否有一个原生的jQuery函数来切换元素? [英] Is there a native jQuery function to switch elements?

查看:152
本文介绍了是否有一个原生的jQuery函数来切换元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以轻松地用jQuery交换两个元素吗?

Can I easily swap two elements with jQuery?

如果可能的话我想用一行来做这件事。

I'm looking to do this with one line if possible.

我有一个选择元素,我有两个按钮可以向上或向下移动选项,我已经有选定的和目的地选择器,我用if做,但我想知道是否有一种更简单的方法。

I have a select element and I have two buttons to move up or down the options, and I already have the selected and the destination selectors in place, I do it with an if, but I was wondering if there is an easier way.

推荐答案

我找到了一种有趣的方法来解决这个问题只使用jQuery:

I've found an interesting way to solve this using only jQuery:

$("#element1").before($("#element2"));

$("#element1").after($("#element2"));

:)

这篇关于是否有一个原生的jQuery函数来切换元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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