Git Product home page Git Product logo

vanilla's Introduction

vanilla

vanilla is a lightweight JavaScript library that works across browsers for processing AJAX requests, event handling, and DOM traversal and manipulation. vanilla works by wrapping JavaScript functions for accessing the Document Object Model into more intuitive syntax. Now your project can be anything but vanilla!

Getting Started

Download & Install

Get started with vanilla by downloading this repo and adding dist/vanilla.js as a script in your program.

<script type="text/javascript" src="./dist/vanilla.js" charset="utf-8"></script>

You can test that it's working by running the following command in the console:

$v( () => alert('thank you for downloading vanilla.') )

Compiling from Source

To compile the source on your own machine, download this repo and run webpack from src/main.js

API

$v (arg) - The wrapper $v is used to create collections of nodes from DOM objects. If arg is a string or HTML element, return a collection of all matched elements. If arg is a function, it is stored to be called when the document has loaded.

.ajax(options) - Perform an asynchronous XMLHTTPRequest using given options object. Return a Promise that can be chained when the request returns.

.attr(key[, val]) - Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element to val.

.children() - Return a collection of children of each element in the set of matched elements.

.each() - Iterate over a DOMNodeCollection, executing a function for each matched element.

.empty() - Remove all child nodes of the set of matched elements from the DOM.

.find(selector) - Get the descendants of each element in the current set of matched elements, filtered by a string containing one or more CSS selectors separated by commas.The returned DOMNodeCollection will contain all the elements in the document that are matched by any of the specified selectors.

.html(html) - If given a string, set the HTML content of each node to be equal to string. Otherwise, return the HTML content of the first element in the set of matched elements.

.append(children) - Insert content to the end of each element in the set of matched elements.

.remove() - Remove the set of matched elements from the DOM.

.on(eventName, callback) - Attach an event handler function for one or more events to the selected elements.

.off(eventName) - Remove an event handler.

.parent() - Return parent of each element in the current set of matched elements.

.addClass(className) - Add class className to each element in the set of matched elements.

.removeClass(className) - Remove a class className from each element in the set of matched elements.

Demo

Live Source

vanilla's People

Contributors

ywenc avatar

Stargazers

 avatar Taichen Rose avatar Cody Benner avatar Jarret Bryan avatar

Watchers

James Cloos 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.