JavaScript Browser Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. Browser snippets include helper functions for selecting, traversing, and manipulating DOM elements, while general-purpose helpers can be found in the JavaScript snippet collection.

  • getSiblings

    JavaScript, Browser

    Returns an array containing all the siblings of the given element.

  • If you need to check if Caps Lock is on when the user is typing in the browser, JavaScript's got you covered.

  • arrayToHTMLList

    JavaScript, Browser

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

  • copyToClipboard

    JavaScript, Browser

    Copies a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

  • copyToClipboardAsync

    JavaScript, Browser

    Copies a string to the clipboard, returning a promise that resolves when the clipboard's contents have been updated.

  • escapeHTML

    JavaScript, String

    Escapes a string for use in HTML.

  • prefix

    JavaScript, Browser

    Prefixes a CSS property based on the current browser.

  • Ever wanted to get the value of an HTML input element as a number? Learn an easy way to do it with this handy trick.

  • observeMutations

    JavaScript, Browser

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

  • on

    JavaScript, Browser

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

  • unescapeHTML

    JavaScript, String

    Unescapes escaped HTML characters.

  • Understand how events work in JavaScript and learn when to use event bubbling, event capturing and event delegation with this short guide.

  • addEventListenerAll

    JavaScript, Browser

    Attaches an event listener to all the provided targets.

  • removeEventListenerAll

    JavaScript, Browser

    Detaches an event listener from all the provided targets.

  • Learn how to attach an event handler to events that is executed at most once in this JavaScript article.