Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/erf/elite

build HTML declaratively using JS 548 bytes
https://github.com/erf/elite

dom dom-api dom-manipulation js-dom js-library

Last synced: about 2 months ago
JSON representation

build HTML declaratively using JS 548 bytes

Awesome Lists containing this project

README

        

# elite

A tiny JavaScript library for building HTML declaratively.

# API

`el(tag, text, attributes, events, children)`

> Creates an HTML element. Arguments after **tag** can be omitted and replaced with **children**. You can also omit `text` and pass the next arguments. Elements can be nested using children.

`get(id)`

> Get element by **id**

`set(element|id, child)`

> Given an **element** or **id**, replace children with a given **child** element(s)

`add(elemnt|id, child)`

> Given an **element** or **id**, append a **child** element(s)

*Please read the code to understand more, it's quite simple!*

## EXAMPLE

```Javascript
const app = el('div', [
el('h1', 'elite', { class: 'elite' }),
el('p', 'a tiny declarative js dom lib', { style: "background: #ffe088; padding: 8pt;" }),
el('div', [
el('button', 'YO', {}, { click: (e) => alert('YO !') }),
]),
el('p', 'Made with ❤ by @apptakk'),
])

set('app', app)

```

Result HTML:

```HTML


elite


a tiny declarative js dom lib



YO

Made with ❤ by @apptakk


```

[example.html](example.html)

[TODO.html](TODO.html)

[https://erf.github.io/elite](https://erf.github.io/elite)

PS !
I've built a slightly more descriptive, but less compact, version of this library called [elite-plus](https://github.com/erf/elite-plus)