Coder Social home page Coder Social logo

bennythadikaran / node.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 76 KB

A tiny helper library for dynamically generating HTML Elements.

License: GNU General Public License v3.0

JavaScript 100.00%
dom dom-helpers dom-manipulation es6 html-generator javascript

node.js's Introduction

Node.js

A tiny helper library for dynamically generating HTML Elements.

Written in vanilla javascript and fully tested.

Usage

import node from "./node.js";

Node.js has just 3 public methods: create, append, remove

node.create takes 3 arguments:

  • Element name,
  • Object of attribute key-values pairs [Optional],
  • Text content to be added [Optional]
let p = node.create("p");
// HTMLElement <p></p>

p = node.create("p", null, "Test Title");
// HTMLElement <p>Test Title</p>

const h1 = node.create(
  "h1",
  {
    id: "title",
    class: "blog-title",
  },
  "Test title"
);
// HTMLElement <h1 id="title" class="blog-title">Test title</h1>

node.append takes 2 arguments

  • An array of elements to be appended.
  • The parent element to append to.
// create some empty nodes
const h1 = node.create("h1");
const h2 = node.create("h2");
const p = node.create("p");

const div = node.create("div");

node.append([h1, h2, p], div);
// returns a div HTMLElement with child elements appended

node.remove takes a single argument

  • Element to be removed
<div>
  <h1 id="title" class="blog-title">DOMGenerator</h1>
</div>
var h1 = document.getElementById("title");

node.remove(h1);

Both node.create and node.append returns an HTML Element allowing them to be combined with other functions.

const div = node.append(
  [
    node.create("p", null, "Para 1"),
    node.create("p", null, "Para 2"),
    node.create("p", null, "Para 3"),
  ],
  node.create("div")
);

document.body.appendChild(node.create("div"));

node.js's People

Contributors

bennythadikaran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.