Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

move list items up and down using javascript

window.onload = function () {
	var upLink = document.querySelectorAll(".up");

	for (var i = 0; i < upLink.length; i++) {
		upLink[i].addEventListener('click', function () {
			var wrapper = this.parentElement;

			if (wrapper.previousElementSibling)
			    wrapper.parentNode.insertBefore(wrapper, wrapper.previousElementSibling);
		});
	}

	var downLink = document.querySelectorAll(".down");

	for (var i = 0; i < downLink.length; i++) {
		downLink[i].addEventListener('click', function () {
			var wrapper = this.parentElement;

			if (wrapper.nextElementSibling)
			    wrapper.parentNode.insertBefore(wrapper.nextElementSibling, wrapper);
		});
	}
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get alphabet as array 
Javascript :: Ajax Form All Data Send 
Javascript :: moment format 23 hour 
Javascript :: js replace all char in string 
Javascript :: pdf darkmode 
Javascript :: jquery set style background image 
Javascript :: how to check element is in viewport 
Javascript :: jquery get today date 
Javascript :: lodash combine permissions 
Javascript :: javascript if undefined 
Javascript :: javascript set input field value 
Javascript :: javascript remove last character from string 
Javascript :: javascript loop through arrya 
Javascript :: javascript set delay 
Javascript :: count 1 to 5 javascript 
Javascript :: check object has value 
Javascript :: moment calculate duration 
Javascript :: login discord token 
Javascript :: jest test array of objects 
Javascript :: trigger event javascript 
Javascript :: create slug in javascript 
Javascript :: node js send file from root dir 
Javascript :: redirect window 
Javascript :: remove same occurances in two different arrays js 
Javascript :: return early pattern for functions javascript 
Javascript :: how to check if a number is float javascript 
Javascript :: npm ERR! Missing script: "eject" react native 
Javascript :: binary to ascii javascript 
Javascript :: react router dom npm 
Javascript :: javascript replace all spaces with dashes 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =