项目作者: harshsinghdev

项目描述 :
A Tiny Dom Manipulation Library
高级语言: JavaScript
项目地址: git://github.com/harshsinghdev/tez-dom.git
创建时间: 2020-06-22T08:51:09Z
项目社区:https://github.com/harshsinghdev/tez-dom

开源协议:MIT License

下载


Tejas

A Tiny DOM Manipulation Library.

Usage

Querying elements

  1. import { qs, qsa } from './tejas.js';
  2. const elem = qs("#test"); // document.querySelector
  3. const elems = qsa("div"); // document.querySelectorAll

Creating elements

  1. import { el, svg } from './tejas.js';
  2. const btn = el('button'); // Output: <button></button>
  3. const foo = el('.class1.class2#foo'); // Output: <div id="foo" class="class1 class2"></div>
  4. const svgEl = svg('svg'); // for creating SVG elements
  5. const path = svg('path');

Note: When you have to append an element to the DOM that’s going to contain several other child elements,
you should first append its child nodes to a DocumentFragment and append the childnodes
to it first and then to the parent element.

Example:

  1. import { el, frag } from './tejas.js';
  2. const createItem = task => {
  3. const item = el('li.item');
  4. item.textContent = task;
  5. return item;
  6. };
  7. const createList = tasks => {
  8. const list = el('ul.list');
  9. const items = tasks.map(createItem);
  10. const fragment = frag();
  11. fragment.append(...items);
  12. list.appendChild(fragment);
  13. return list;
  14. };
  15. document.body.appendChild(createList(['Buy Milk', 'Buy Tea', 'Water Plants']));

Handling events

  1. import { on, off, ready } from './tejas.js';
  2. const greet = () => console.log("hello world");
  3. on(button, "click", greet); // addEventListener
  4. off(button, "click", greet); // removeEventListener
  5. ready(() => {
  6. // Your code which you want to run after the DOM has loaded.
  7. });

Attributes and CSS styling

  1. import { setStyle, attr } from './tejas.js';
  2. setStyle(elem, { color: "red", background: "blue" }); // adding multiple styles to an element
  3. console.log(attr(elem, "id")); // getAttribute
  4. attr(elem, "id", "test"); // setAttribute
  5. attr(elem, "disabled", false); // removeAttribute

Made With in Bharat