Giter Club home page Giter Club logo

domanipulation's Introduction

DOManipulation

Description

DOManipulation is a DOM manipulation library inspired by JQuery and written in vanilla JavaScript. Supported functionality includes:

  • Create DOM Elements
  • Select DOM Elements by HTML tag, id or class
  • Add and Remove event handlers
  • Append elements
  • Make AJAX requests

Using DOManipulation

  • Clone the library in your project
  • Simply import domanipulation.js with a script tag in the header of your HTML.

API

$d

The $d wrapper has three main uses :

  • Creates a new DOMNodeCollection object. $d("<li>");
  • Takes an HTMLElement and wraps it to return an DOMNodeCollection object
  • Selects elements via tags, css selectors or id.

$d(".hidden") or $d("div") or $d("#red-item")

DOM Traversal

find(selector). Returns a DOMNodeCollection of all the nodes that match the argument that are children of the DOMNodeCollection nodes.  

children().

Returns a DOMNodeCollection of all children of all nodes within the DOMNodeCollection.

$d(".hidden").children()

parent()

Returns a DOMNodeCollection of the parent of all nodes within the DOMNodeCollection.
$d(".hidden").parent().

remove()  

Removes the element from the DOM.

Event Handling

on(action,cb). Installs an 'action' event handler. When triggered runs the cb callback. $d(".addtodo-button").on("click", () => { const inp = $d(".hidden") inp.removeClass("hidden") inp.addClass("shown"); });

off(action). Removes the 'action' listener from the DOM

Manipulation

*addClass(className)

Adds a class attritube to all nodes within the DOMNodeCollection.
todoTitle.addClass("todo-title");

*removeClass(className)

Remove a class attritube of all nodes within the DOMNodeCollection.
todoTitle.removeClass("todo-title");

  • append(arg) arg can be a string, HTMLElement, or DOMNodeCollection object Appends the outerHTML of each element in the argument to the innerHTML of ALL nodes within the DOMNodeCollection. todoTitle.append(${title}); newTodo.append(subButton); where subButton is an instance of DOMNodeCollection

*empty()

Clears the content from all nodes within the DOMNodeCollection.

*attr(key, [value])

Accepts a key and optional value. If the value exists, it will add that value and key to all nodes within the DOMNodeCollection. If there is no value, it will return the value corresponding for the key of the first node.

domanipulation's People

Contributors

georgesco94 avatar

Stargazers

Alex Harris avatar David Veytsman avatar Steven Stef avatar Christopher Lew 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.