• 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

One-Liner If-Else Statements

One-Liner If-Else Statements

Instead of writing an if-else on multiple lines, you can use the ternary operator to write the whole statement with one line of code.

Basics

Get the currently selected text with JavaScript

Get the currently selected text

Use Window.getSelection() and Selection.toString() to get the currently selected text.

Text Effects

Javascript Conditionals Explained

Javascript Conditionals Explained

Conditional statements control behavior in JavaScript and determine whether or not pieces of code can run.

Basics

Get the default value of a CSS property with JavaScript

Get the default value of a CSS property

The following function returns the default value of CSS property for given tagName.

CSS

How to loop through arrays and array-like objects in JavaScript

Loop through arrays and array-like objects

Here is how to loop through arrays and array-like objects using JavaScript.

Miscellaneous

How to Get the Query String in JavaScript

How to Get the Query String in JavaScript

When you’re working with JavaScript, sometimes you need to access query string parameters in your script.

Miscellaneous

Check if the given year is a leap year

Check if the given year is a leap year

Use new Date(), setting the date to February 29th of the given year. Use Date.prototype.getMonth() to check if the month is equal to 1.

Time & Date

JavaScript Functions Explained

JavaScript Functions Explained

JavaScript functions are reusable blocks of code that perform a specific task, taking some form of input and returning an output.

Basics

Submit a form with Ajax

Submit a form with Ajax

The following function submits the data of formEle to the back-end using an Ajax request

Ajax

Get and Set Classes On An Element

Get and Set Classes On An Element

Get all of the classes on an element as a string, add a class or classes, or completely replace or remove all classes.

CSS

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 18
  • Go to page 19
  • Go to page 20
  • Go to page 21
  • Go to page 22
  • 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