• 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

Capitalize the first letter of a string

Capitalize the first letter of a string

This snippet capitalizes the first letter of a string.

Miscellaneous

Redirect to a specified URL

Redirect to a specified URL

Use Window.location.href or Window.location.replace() to redirect to url. Pass a second argument to simulate a link click (true – default) or an HTTP redirect (false).

Miscellaneous

Preview an image before uploading it

Preview an image before uploading it

Here’s how to use JavaScript to preview an image before uploading it.

Image Effects

Get an attribute on an element

Get an attribute on an element

Use Element.getAttribute() to get an attribute (including data attributes) on an element.

Miscellaneous

Optional Chaining to Prevent Crashes

Optional Chaining to Prevent Crashes

If you access an undefined property, an error is produced. This is where optional chaining comes to the rescue.

Miscellaneous

Return all elements in an array except for the first one

Return all elements in an array except for the first one

Return Array.prototype.slice(1) if Array.prototype.length is more than 1, otherwise, return the whole array.

Miscellaneous

JavaScript Objects Explained

JavaScript objects are variables that contain multiple data values. The values within a JS object are known as properties. Objects use keys to name values, much like how is done with variables.

Basics

Paste an image from the clipboard

Paste an image from the clipboard

Here’s how to paste an image from your computer’s clipboard using JavaScript.

Image Effects

Highlight an element when dragging a file over it

Highlight an element when dragging a file over it

We will highlight the element when user drags a file over it. For example, the element will have a dashed border which can be simulated by a CSS class.

Miscellaneous

Get the computed style of an element

Get the computed style of an element

Get the actual computed style of an element. This factors in browser default stylesheets as well as external styles you’ve specified.

CSS

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

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2021 JavaScriptSource.com

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