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

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Forum
  • 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

Select an element or list of elements

Select an element or elements by given ID, class name, tag name, or CSS selector.

CSS

Dynamically changing the text color based on background color contrast

Get the contrasting color for any hex color.

Text Effects

Check if at least one element of values is included in arr

Use Array.prototype.some() and Array.prototype.includes() to check if at least one element of values is included in arr.

Miscellaneous

Check If an Element is Visible in the Viewport

In this tutorial, you’ll learn how to check if an element is visible in the viewport using JavaScript.

CSS

Press shift and enter for a new line

In some cases such as an inline editable element, or a messaging application, you would like to submit the data when user presses Enter. The only way to generate a new line is to press Shift and Enter.

Miscellaneous

Get the value of a cookie

In order to retrieve specific cookie value, we just need to get string that is after “; {name}=” and before next “;”.

Cookies

Insert an HTML string after the end of the specified element

Use Element.insertAdjacentHTML() with a position of ‘afterend’ to parse htmlString and insert it after the end of el.

Miscellaneous

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

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

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

Time & Date

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Interim pages omitted …
  • Go to page 12
  • Go to Next Page »

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Copyright © 2021 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us