JSFiddle - React, Tailwind, and code Playground
by dustinpoissant
HTML
<button onclick="$('div').each(function(x){x.style.visibility='visible';});">Click Here</button>
<div id="display" class="world">Hello World</div>
<div style="visibility: hidden;">Hidden</div>
JavaScript
function $() {
var selections = [];
for (var a = 0; a < arguments.length; a++) {
var objects = arguments[a].split(" ");
temp = [];
temp.push(new Array(document));
for (var o = 0; o < objects.length; o++) {
temp.push(new Array());
if (objects[o][0] == "#") {
for (var i = 0; i < temp[temp.length - 2].length; i++) {
temp[temp.length - 1].push(temp[temp.length - 2][i].getElementById(objects[o].slice(1)));
}
} else if (objects[o][0] == ".") {
for (var i = 0; i < temp[temp.length - 2].length; i++) {
var temp2 = temp[temp.length - 2][i].getElementsByClassName(objects[o].slice(1));
for (var t2 = 0; t2 < temp2.length; t2++) temp[temp.length - 1].push(temp2[t2]);
}
} else {
for (var i = 0; i < temp[temp.length - 2].length; i++) {
var temp2 = temp[temp.length - 2][i].getElementsByClassName(objects[o]);
for (var t2 = 0; t2 < temp2.length; t2++) temp[temp.length - 1].push(temp2[t2]);
}
}
}
for(var t=0;t<temp[temp.length-1].length;t++){
selections.push(temp[temp.lenght-1][t]);
}
}
return selections;
}
Array.prototype.each = function (f) {
var temp = [];
for (var i = 0; i < this.length; i++) temp[i] = f(this[i]);
return temp;
};