• 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

Detecting when a visitor has stopped scrolling

Detecting when a visitor has stopped scrolling

This snippet listens for scroll events using addEventListener, sets a delayed timeout function to run a few milliseconds after the event, but with each scroll event it clears that timeout function so it doesn’t run.

Navigation

Get the size of an image

Get the size of an image

These snippets will get the height and width of an image, one when it is loaded and another when the image is not loaded yet.

Page Details

Check if the given number is odd

Check if the given number is odd

Check whether a number is odd or even using the modulo (%) operator. Return true if the number is odd, false if the number is even.

Math Related

Selecting Elements By Class Name

Selecting Elements By Class Name

To select elements by a given class name, you use the getElementsByClassName() method

CSS

Stop an iframe or HTML5 video from playing

Stop an iframe or HTML5 video from playing

This snippet stops or pauses YouTube, Vimeo and HTML5 videos when the content area is close

Multimedia

Resize an iframe to fit its content

Resize an iframe to fit its content

This snippet gets the height of an iframe’s content and then sets the height of the iframe to match.

Miscellaneous

Calculate the nth root of a given number

Calculate the nth root of a given number

Use Math.pow() to calculate x to the power of 1/n which is equal to the nth root of x.

Math Related

Selecting an Element By Id

Selecting an Element By Id

Select an element that matches the id using the getElementById() method.

CSS

Get the amount of time from now for a date

Get the amount of time from now for a date

Here is a vanilla JS alternative to the moment.js timeFromNow() method.

Time & Date

Serialize form data into a query string

Serialize form data into a query string

This function serializes the form data which consists of names and values of its fields.

Forms

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 27
  • Go to page 28
  • Go to page 29
  • Go to page 30
  • Go to page 31
  • 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