Javascript jQuery将sibblings元素移动到所选元素之前

Javascript jQuery将sibblings元素移动到所选元素之前,javascript,jquery,methods,siblings,Javascript,Jquery,Methods,Siblings,我有这个html: 正文 如果您只想切换位置,请在它们之间循环并执行以下操作: $('.radio matrix')。每个(函数(){ //“this”是radio matrix类的实例 $(this).next().insertBefore(this); //或 $(this).兄弟姐妹('p').insertBefore(this); }); 正文 在之前使用,如下所示: $('input.radio matrix')。在($('p'))之前 正文 这将反转所选元素($selec

我有这个html:


正文


如果您只想切换位置,请在它们之间循环并执行以下操作:

$('.radio matrix')。每个(函数(){
//“this”是radio matrix类的实例
$(this).next().insertBefore(this);
//或
$(this).兄弟姐妹('p').insertBefore(this);
});

正文


之前使用
,如下所示:

$('input.radio matrix')。在($('p'))之前

正文


这将反转所选元素(
$selectedElement
)及其后面的元素

$(文档).ready(函数(){
变量$selectedElement=$(“.radio矩阵”);
var$selectedElementSibling=$(“.radio matrix”).next();
$selectedElementSibling.after($selectedElement);
});

正文


在选择
后,您想做什么?您没有解释如果其中一个以上,或者如果页面中的其他地方存在
,则哪些预期结果将不起作用(非常感谢!)你的方法很好,因为我有几个标签,这样它就适用于每一个!对……当存在多个这样的组时,如果不循环和处理特定实例,就会出现问题