ShortJS is a JavaScript function pack that rewraps common JavaScript functions to make them easier to type and read, similar to jQuery.
$(selector): Equivalent todocument.querySelector(selector).$$(selector): Equivalent todocument.querySelectorAll(selector).
on(element, event, callback): Equivalent toelement.addEventListener(event, callback).off(element, event, callback): Equivalent toelement.removeEventListener(event, callback).
hide(element): Setselement.style.displayto'none'.show(element): Setselement.style.displayto an empty string.toggle(element): Toggles theelement.style.displaybetween'none'and''.
create(tagName): Equivalent todocument.createElement(tagName).append(parent, child): Equivalent toparent.appendChild(child).prepend(parent, child): Equivalent toparent.insertBefore(child, parent.firstChild).remove(element): Removes theelementfrom its parent.empty(element): Removes all child nodes from theelement.
addClass(element, className): Adds the specified class to theelement.removeClass(element, className): Removes the specified class from theelement.toggleClass(element, className): Toggles the specified class on theelement.hasClass(element, className): Checks if theelementhas the specified class.
attr(element, attributeName, value): Gets or sets the value of the specified attribute on theelement.data(element, key, value): Gets or sets the value of the specified data attribute on theelement.
text(element, content): Gets or sets the text content of theelement.html(element, content): Gets or sets the HTML content of theelement.
val(element, value): Gets or sets the value of theelement(for inputs, selects, etc.).
css(element, styles): Sets the CSS styles of theelement.width(element, value): Sets the width of theelement.height(element, value): Sets the height of theelement.
ajax(url, options): Performs an AJAX request using the fetch API.
"Vanilla JS" refers to using plain, native JavaScript without any additional libraries or frameworks. ShortJS aims to provide a more concise and readable way to write common JavaScript code, similar to how jQuery simplifies DOM manipulation.
To use ShortJS functions, simply include the ShortJS script in your HTML file:
<script src="https://cdn.jsdelivr.net/gh/tlochsta/ShortJS@main/short.js"></script>Then, you can use the functions in your JavaScript code:
const element = $('.my-element');
hide(element);ShortJS is licensed under the MIT License. See LICENSE for more information. Created by tlochsta