Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/eldoy/sord

Microscopic replacement for 'document.querySelector' and 'document.querySelectorAll'
https://github.com/eldoy/sord

Last synced: 6 days ago
JSON representation

Microscopic replacement for 'document.querySelector' and 'document.querySelectorAll'

Awesome Lists containing this project

README

        

# SORD
Microscopic replacement for `document.querySelector` and `document.querySelectorAll`.

Only 182 bytes minified.

### Install
In Node.js:
`npm i sord`

In the browser:
```html
function s(a,b,c,x,y,z,f,i){if(typeof a=='object'){x=a;y=b}else{x=document.body;y=a}z=x.querySelectorAll(y);if(f=typeof b=='function'?b:c)for(i=0;i<z.length;)f(z[i++],x);return z[0]}
```

### Usage
```javascript
// From module
var s = require('sord')

// Find HTML element
s('#app')

// Find element inside el
s(el, 'input')

// Use callback instead of querySelectorAll
s('p', el => el.textContent = 'hello')

// Callback with root, default root is document.body
s(document, 'p', (el, root) => {
el.textContent = 'hello'
root.style.opacity = 0.5
})
```
ISC licensed. Enjoy!