Answers for "how to add an event for every element selected in javascript"

6

How to insert an element after another element in JavaScript without using a library?

//insert new Element after some reference Element
function insertAfter(newElement, referenceElement) {
    referenceElement.parentNode.insertBefore(newElement, referenceElement.nextSibling);
}

//example usage
var newElement = document.createElement("div");
    newElement.innerHTML = "my New Div Text";
var myCurrentElement= document.getElementById("myElementID");
    insertAfter(newElement, myCurrentElement);
Posted by: Guest on July-31-2019
0

how to add class to element on mouseclick with js

// element.classList.add("newClass");
// or
// element.className += "newClass";

// Example

document.querySelector("button").onclick = function addNewClass() {
  document.querySelector(".elementToChange").classList.add("newClass");
}
Posted by: Guest on May-09-2020

Code answers related to "how to add an event for every element selected in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language