0.3.2 • Published 4 years ago

k-dom v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

k-dom

Helper functions for DOM manipulation

Installation

npm install k-dom

Quick Start

import {
  $,
  $$,
  DocFrag,
  cloneNode,
  clearNode,
  replaceNode,
  removeNode,
  cloneScript,
  createStyle,
  filterVisible,
  DOM,
  scrollTo
} from "k-dom";

$(".foo").addClass("foo", "bar", "zoo");

$$(".bar").forEach((el) => el.removeClass("foo", "bar"));

// Create a DocumentFragment with children
const frag = DocFrag(
  document.createElement("div"),
  document.createElement("ul"),
  document.createElement("p")
);

const clonedEl = cloneNode($(".foo"));

// Remove all its children
clearNode(clonedEl);

// Replace myElement with clonedEl
replaceNode(clonedEl, myElement);

removeNode(clonedEl);

const script = cloneScript($("script"));

const style = createStyle(`
  body {
    color: red;
  }
`);

// Visible UI elements
const visibleElements = filterVisible(document.body.children);

// HTML to DOM Element
const ul = DOM(`
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
  </ul>
`);

// Set scrollTop of document body
scrollTo(document.body, 100);
0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.2

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

9 years ago

0.1.0

9 years ago