• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details

Replace a Class of an Element

Replace a Class of an Element

To replace a class of an element with a new one, you use the replace() method of the classList property of the element.

CSS

Toggle password visibility

Toggle password visibility

In order to show the password, we turn the password element to an usual textbox whose type attribute is text.

Passwords

Get a formatted list of months

Get a formatted list of months

Here’s a trick for getting back a formatted month name (like January or Jan).

Time & Date

Insert an HTML string before the start of the specified element

Insert an HTML string before the start of the specified element

Use Element.insertAdjacentHTML() with a position of ‘beforebegin’ to parse htmlString and insert it before the start of el.

Miscellaneous

Check If an Element contains a Class

Check If an Element contains a Class

To check if an element contains a class, you use the contains() method of the classList property of the element.

CSS

Clone an element

Clone an element

Using the cloneNode(true) method will deep copy a given element.

Miscellaneous

Get the date for a specific day of the week

Here’s a way to get the date for the next occurrence of a specific day of the week.

Time & Date

Remove an element from the DOM

Remove an element from the DOM

Use Element.parentNode to get the given element’s parent node. Use Element.removeChild() to remove the given element from its parent node.

Miscellaneous

Toggle a Class of an Element

Toggle a Class of an Element

To toggle a class of an element, you use the toggle() method of the classList property of the element.

CSS

Count the number of characters of a textarea

Count the number of characters of a textarea

Count the number of characters by handling the input event which is triggered if the value of element is changed.

Forms

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 23
  • Go to page 24
  • Go to page 25
  • Go to page 26
  • Go to page 27
  • Interim pages omitted …
  • Go to page 36
  • Go to Next Page »

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers