A lightweight DOM Manipulation library for VanillaJS
ElementsJS is a lightweight jquery-like library for simplifying DOM Manipulation in Vanilla JS code-bases. Unlike jQuery, it only extends the behaviour of basic Javascript functionality, without adding any middleware components.
- Lightweight (5.8K minified)
- Syntax identical to jQuery
- Supports chaining method calls
- Simplifies event-listener management
- Works with any JS flavor or library
- Easily Extensible
<script src="https://cdn.jsdelivr.net/gh/communit-team/ElementsJS@main/dist/elements.min.js"></script>
let $el = Div().addClass('my-div').attr('id', 'hello-world').html("Hello World");
let $el = El('a').attr('src', '/my/path').html("Click Me");
let $el = Div().addClass('my-div');
$el.on('event-triggered', (e) => { // DO SOMETHING });
$el.dispatch('event-triggered', {data: "success"});
let $el = Div().addClass('my-div').attr('id', 'hello-world');
let $title = Span().addClass('title').html('My Title');
let $text = Span().addClass('text').text('My Text');
$el.html($title).append($text);
let $el = Div().addClass('my-div').attr('id', 'hello-world');
let $title = Span().addClass('title').html('My Title');
let $text = Span().addClass('text').text('My Text');
$el.html($title).append($text);
// query title in parent Element
El('.title', $el)
// query title in body
El('.title')
// create a pure JS element
let $el = document.createElement('div')
// create an ElementsJS element
let $title = Span().addClass('title').html('My Title');
// apply ElementJS methods and elements to vanilla JS
$el.html($title).addClass('some-class some-other-class').addClass('another-class');
const Icon = function(v) { return El('i').addClass('icon').attr('data-icon-type', v); }
// create element
let icon = Icon('arrow-up')
// get data-icon-type
icon.dataset.iconType
const IconBig = function(v) { return Icon(v).addClass('icon-big') };