Js 更换html同一父元素下子元素的位置
2024-10-20 16:46:37
//更换两个元素的位置
var exchange=function (el1, el2) {
var ep1 = el1[0].parentNode,
ep2 = el2[0].parentNode,
index1 = Array.prototype.indexOf.call(ep1.children, el1),
index2 = Array.prototype.indexOf.call(ep2.children, el2);
ep2.insertBefore(el1, ep2.children[index2]);
ep1.insertBefore(el2, ep1.children[index1]);
}
exchange($(".class1"),$(".class2"));
//class1与class2要是相同父级下的元素
例:
执行后 exchange($(".btns .ok"),$(".btns .cancel"));
最新文章
- java.lang.NumberFormatException: For input string: ";1608020001 "; 错误
- swift的运算符
- js事件捕获,事件冒泡,事件委托以及DOM事件流
- ZOJ 1041 Transmitters
- mapreduce任务中Shuffle和排序的过程
- Tornado,表单处理,一样在行
- HTML5表单内元素的required属性
- [PHP]MemCached高级缓存
- Timer.3 - Binding arguments to a handler
- Codeforces 442C Artem and Array(stack+贪婪)
- paper资料
- 微信小程序如何开发制作
- web.config中的configSource
- harris角点检测的简要总结
- volatility内存取证
- trinitycore 魔兽服务器源码分析(二) 网络
- npm 安装React Devtools调试工具
- python的字符串连接操作符+
- ios开发UI篇--UIStepper
- C语言不定型参数函数定义