UNPKG

jessquery

Version:

Modern JavaScript is pretty good, but typing document.querySelector() is a pain. This is a tiny library that makes DOM manipulation easy. jQuery is around 80kb (30kb gzipped), while this is only around 8kb (3.5kb gzipped). Lots of JSDoc comments so it's s

42 lines (34 loc) 1.19 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>MoveTo Before Test</title> </head> <body> <div id="originalElement">Original Element</div> <div id="parent"> <div id="child">Child</div> </div> <div id="testContainer"></div> <script type="module"> import { $ } from "../index.js" function moveToBeforeTest() { const output = document.createElement("div") document.getElementById("testContainer").appendChild(output) const el = $("#originalElement") el.moveTo("#child", { position: "before" }) const firstChildElement = document.querySelector("#parent").firstElementChild if (firstChildElement && firstChildElement.id === "originalElement") { output.style.color = "green" output.textContent = "moveTo before test PASSED" } else { output.style.color = "red" output.textContent = "moveTo before test FAILED" } } moveToBeforeTest() </script> </body> </html>