Skip to content

Instantly share code, notes, and snippets.

@derek-dchu
derek-dchu / jQuery_swap_elements
Last active December 12, 2023 20:17
Swap two dom elements using jQuery
/**
* Swap two elements within a multiple selector with index a and b
* @param a: index of the first element
* @param b: index of the second elemnt
*
* DEMO at http://jsfiddle.net/derekhu/8rauhuxh/#base
*/
function swapElement(elements, indexA, indexB) {
// Make sure indexA is smaller than indexB
if (indexA > indexB) {