JSFiddle - React, Tailwind, and code Playground
by Alexander
HTML
<h5>Simple jQuery like lib</h5>
<input type="text">
<div>Typed text:
<span>span text</span>
</div>
JavaScript
"use strict";
console.clear();
//var $ = document.querySelector.bind(document);
Element.prototype.on = Element.prototype.addEventListener;
Element.prototype.$ = function (selector){ return $(selector, this) }
function $(selector, ctx) {
//return [].slice.call((ctx || document).querySelectorAll(selector));
return (ctx || document).querySelectorAll(selector);
}
// Return [0] element
$.$ = (selector, ctx) => $(selector, ctx)[0];
var $div = $("div")[0],
$input = $.$("input");
$input.on("keyup", () => {
const $span = $div.$('span')[0];
$span.innerText = $input.value;
});