Greasemonkey script to move an element into another element?

喜欢而已 提交于 2019-12-05 19:08:20

To swap the first and last div.clearfixs, given that HTML, use the querySelector, insertBefore, and appendChild functions.

Here is a complete Greasemonkey script that does that:

// ==UserScript==
// @name     _Swap first and last div.clearfix
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    none
// ==/UserScript==

var container    = document.querySelector ("fieldset");
var firstTargDiv = container.querySelector ("fieldset > div.clearfix:first-child");
var lastTargDiv  = container.querySelector ("fieldset > div.clearfix:last-child");

//-- Swap last to first.
container.insertBefore (lastTargDiv, firstTargDiv);

//-- Move old first to last.
container.appendChild (firstTargDiv);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!