30 seconds of code

Browser

Click on a snippet card to view the snippet.

UUIDGeneratorBrowser

Generates a UUID in a browser.

arrayToHtmlList

Converts the given array elements into <li> tags and appends them to the list of the given id.

bottomVisible

Returns true if the bottom of the page is visible, false otherwise.

counter

Creates a counter with the specified range, step and duration for the specified selector.

createElement

Creates an element from a string (without appending it to the document). If the given string contains multiple elements, only the first one will be returned.

createEventHub

Creates a pub/sub (publish–subscribe) event hub with emit, on, and off methods.

currentURL

Returns the current URL.

detectDeviceType

Detects whether the website is being opened in a mobile device or a desktop/laptop.

elementContains

Returns true if the parent element contains the child element, false otherwise.

elementIsVisibleInViewport

Returns true if the element specified is visible in the viewport, false otherwise.

formToObject

Encode a set of form elements as an object.

getImages

Fetches all images from within an element and puts them into an array

getScrollPosition

Returns the scroll position of the current page.

getStyle

Returns the value of a CSS rule for the specified element.

hasClass

Returns true if the element has the specified class, false otherwise.

hide

Hides all the elements specified.

httpsRedirect

Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.

insertAfter

Inserts an HTML string after the end of the specified element.

insertBefore

Inserts an HTML string before the start of the specified element.

isBrowserTabFocused

Returns true if the browser tab of the page is focused, false otherwise.

nodeListToArray

Converts a NodeList to an array.

observeMutations

Returns a new MutationObserver and runs the provided callback for each mutation on the specified element.

off

Removes an event listener from an element.

on

Adds an event listener to an element with the ability to use event delegation.

onUserInputChange

Run the callback whenever the user input type changes (mouse or touch). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops).

prefix

Returns the prefixed version (if necessary) of a CSS property that the browser supports.

recordAnimationFrames

Invokes the provided callback on each animation frame.

redirect

Redirects to a specified URL.

runAsync

Runs a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI.

scrollToTop

Smooth-scrolls to the top of the page.

serializeForm

Encode a set of form elements as a query string.

setStyle

Sets the value of a CSS rule for the specified element.

show

Shows all the elements specified.

smoothScroll

Smoothly scrolls the element on which it's called into the visible area of the browser window.

toggleClass

Toggle a class for an element.

triggerEvent

Triggers a specific event on a given element, optionally passing custom data.