Download
Get the latest version of Rilla.js from the GitHub repository.
- Minified: view raw · download map
- Unminified: view raw · download script
Rilla.js is a lightweight JavaScript utility library designed to simplify development and improve the developer experience.
Warning: This early build (v0.1) is still in development and may undergo significant changes without prior notice, potentially breaking your code. Use it for testing purposes only.
Get the latest version of Rilla.js from the GitHub repository.
Alternatively, you can start using it via CDN:
Simply add the rilla.min.js script tag in the <head> section of your HTML file:
Select DOM elements using id, className, tagName, etc:
As a method to an element to select its child or children:
Select a child or children of an element:
Chain the selected element or elements with vanilla JS or Rilla methods:
An internal helper function to easily get an element passed as an argument:
Execute a callback function or logic on an element while maintaining method chaining:
Find a parent element at the specified level:
Find all child elements at the specified level:
Get all sibling elements:
Wrap an element with a new element:
Unwrap an element from its parent if it's not <html> or <body>.
If an only child, delete the parent element:
If not an only child, move the element outside the parent:
Render HTML content into the element, replacing any existing content:
Create and insert an element as the first child(ren) of the element:
Create and insert an element as the last child(ren) of the element:
Create and insert an element before the element:
Create and insert an element after the element:
GET the textContent of an element:
SET the textContent of an element:
GET the value of an element:
SET the value of an element:
GET the innerHTML of an element:
SET the innerHTML of an element:
GET the outerHTML of an element:
SET the outerHTML of an element:
Add an event listener to a element:
Remove all the event listeners of an element:
Remove all listeners for a specific event:
Remove a specific event listener:
Add preventDefault() to an event listener:
Add stopPropagation() to an event listener:
Execute code when the DOM is fully loaded and ready:
Execute code when the entire page (including all resources) has finished loading:
GET the value of an attribute:
SET the value of an attribute:
Sample HTML element:
GET all the data attributes of an element:
GET a specific data attribute of an element:
SET a data attribute of an element:
DELETE a specific data attribute of an element:
DELETE all the data attributes of an element:
Sample CSS of an element:
GET the computed style value of a specific css property of an element:
SET the computed style value of a specific css property of an element:
SET using a function callback:
SET multilple properties (object):
Sample HTML of an element:
GET all the classes of an element:
CHECK if a specific class exists:
SET the class of an element:
DELETE the class of an element:
Check if an element has a specific class. Returns a boolean:
Add a class/classes to an element:
Remove a class/classes from an element:
Toggle the class/classes of an element:
Converts a string to title case with automatic handling of minor words and special cases.
Minor words handled: a, an, and, as, at, but, by, for, if, in, is, nor, of, on, or, per, so, the, to, up, via, vs, vs., yet.
As a function:
Everything above, as a method:
Converts a string to sentence case (first letter capitalized, rest lowercase):
Everything above, as a method:
Converts a string to kebab-case (lowercase with hyphens separating words).
Everything above, as a method:
Shorten a string to a specified character limit, as a function:
Everything above, as a method:
Shuffle an array using the Fisher-Yates algorithm, as a function:
Everything above, as a method:
Show (hidden) elements with customizable display types and transition, as a function:
As a method:
Hide elements, as a function:
As a method:
Toggle element visibility with customizable display types and transition, as a function:
As a method:
Show elements with smooth CSS animations. Handles animation timing, cleanup, callback, and user motion preferences.
Add the following function to your script:
This function assumes your elements are hidden using a CSS class .hidden:
Modify the animation duration by replacing the default 200ms. Also if your app doesn't support the toggle setting for enabling/disabling motion effects, you can remove the condition for isMotionEffectsEnabled like so:
Lastly, this requires any of the following CSS:
Hide elements with smooth CSS animations. Handles animation timing, cleanup, callback, and user motion preferences.
Add the following function to your script:
This function assumes your elements would be hidden using a CSS class .hidden:
Modify the animation duration by replacing the default 200ms. Also if your app doesn't support the toggle setting for enabling/disabling motion effects, you can remove the condition for isMotionEffectsEnabled like so:
Lastly, this requires any of the following CSS:
Toggle elements with smooth CSS animations:
Swap two "screens" i.e. elements visibility with smooth slide transition:
Swap two "screens" i.e. elements visibility with smooth zoom transition:
This method uses the helper function $rillaStore.
GET the value of a localStorage key:
SET the value of a localStorage key:
DELETE a localStorage key and its value:
This method uses the helper function $rillaStore.
GET the value of a sessionStorage key:
SET the value of a sessionStorage key:
DELETE a sessionStorage key and its value:
Add the following CSS classes to your stylesheet:
Then, to make a container (or an element) draggable, add the .draggable class to the container, and .drag-handle to the element you want to assign as the handle:
GET the full page URL, or GET a specific URL property (protocol, hostname, pathname, etc.):
Valid properties: href, origin, protocol, host, hostname, port, pathname, search, hash, username, password.
GET a URL parameter value:
SET a URL parameter:
GET the page hash fragment:
SET the page hash fragment:
Add target="_blank" rel="noopener noreferrer" attributes to anchor tags inside the element:
GET the current page title:
SET a new page title:
Explore the source code, report issues, or contribute on GitHub.
Rilla.js is open source and distributed under the MIT License.