The primary use of JavaScript is to write functions that are embedded in or included from HTML pages and that interact with the Document Object Model (DOM) of the page.


Vanilla JS equivalent of jQuery text

17 Feb, 2023
The Vanilla JS equivalent of jQuery's text() method would be to set the textContent property of a DOM element.

Vanilla JS equivalent of jQuery css

17 Feb, 2023
In jQuery, you can set CSS properties on an element using the css() method. To achieve the same thing in vanilla JavaScript, you can use the style property of the element.

Vanilla JS equivalent of jQuery attr

17 Feb, 2023
In jQuery, the attr method is used to get or set the value of an attribute for an element. In vanilla JavaScript, you can use the getAttribute and setAttribute methods to achieve the same...

Vanilla JavaScript equivalent of jQuery click

13 Jan, 2023
In vanilla JavaScript, the equivalent of the jQuery click function would be the onclick property. The onclick property in JavaScript is an event property of HTML elements that allows you to specify a...

in_array equivalent in JavaScript

12 Jan, 2023
In JavaScript, the equivalent of the PHP function in_array() is the includes() method, which is used to check if an array contains a certain value.

Vanilla JS equivalent of jQuery prepend

2 Jan, 2023
Insert content to the beginning of an element. Vanilla JS equivalent prepends to a single element, to prepend to multiple elements you need a loop. Same applies to append.

Vanilla JS equivalent of jQuery find

30 Dec, 2022
The Vanilla JavaScript equivalent of jQuery's .find() method is the .querySelectorAll() method. The function allows us to search through the descendants of these elements in the DOM tree and...

Javascript: object keys and values to html table

14 Jun, 2021
Convert javascript object into html table, where keys are in the first column and values are in the second column. This uses plain javascript so you can use it anywhere.

Explode / split string in ES6

15 Jul, 2020
How to split string in ES6. I would suggest the method of using split function from lodash. In modern JavaScript frontend you use a lot of dependencies and lodash is used in almost every project....

Validate Date in JavaScript

15 Apr, 2020
How to find out if a Date is indeed a valid Date. Simply instance check will not do it, the date might be "Invalid Date".

Create and Post HTML Form using Javascript

20 Mar, 2019
This snippet creates html form and submits it, the same way as browser submits form "with redirect". If you need the redirect not an ajax solution, for example credit card payment.

Convert to Integer in JavaScript

8 Nov, 2018
There are multiple ways to convert values to integer in javascript. Using Math.trunc gives the most accurate results.

Webpack: Remove comments from compressed css

1 Jun, 2017
You can minify css with optimize-css-assets-webpack-plugin, but by default some comments are left untouched. If you want to remove all comments you have to use an option for the cssnano, that is used...

Javascript: move item to end of array (of objects), by property value

29 May, 2017
The snippet shows how to move item to the end of array. In a case where we have an array of objects and we want to move the array item by property value. In this example I am using lodash/underscore...

JavaScript ES6: Clone Object

13 May, 2017
The Object.assign() method copies all properties from one or more source objects to a target object. It returns the target object. This can be used for cloning an object in ES6, just create an empty...

webpack: Minify CSS in production

14 Mar, 2017
You can achieve this by adding a library that supports css minify to "webpack.config.js". In this snippet I use "optimize-css-assets-webpack-plugin" which uses cssnano for minimizing by default. The...

Delete object key and value in javascript

12 Oct, 2016
Deleting object value with key in javascript. For this you can use the delete operator. Permits you to remove a property from an object.

Minify JavaScript from command line

8 Mar, 2016
This snippet shows how to minify javascript files from command line. Minifying JavaScript is useful in many respects. Most important are security and performance. Security is increased due to the...

Get previous / next element using JavaScript

8 Mar, 2016
This snippet shows how to get element next to your element / selector. This a part of dom traversal. Using javascript for next element parsing can be used to create some powerful dynamic content. I...

AddThis: Popup instead of hover box

25 Nov, 2015
AddThis is an awesome social sharing tool. It is fully customizable. I suggest using addthis module for loading add this library, this has performance options for the javascript loading.

Get cursor position in CKEditor

12 Jun, 2015
Get cursor position in CKEditor is simple if you know some facts. You have to have the instance initiated, so simple jQuery ready would not work. You can get selection and use that functionality to...

Alter URL GET parameters using JavaScript

14 Aug, 2013
This function alters url get parameters using javascript. The function takes to consideration all aspects of url (parameter existis, hash, parameter doesn't exist). For an example if you need to be...

jQuery - Check if selector is disabled

7 Mar, 2013
You can use "is" to see if the form element is disabled.

Message before leaving the page - JavaScript / jQuery

8 Feb, 2013
How to display message before closing the page or moving to another page. Don't use this to annoy people. Sometimes this functionality is still useful, for an example if you have some sort of unsaved...

Get URL variables with JavaScript

21 Nov, 2012
This function gets URL variables in JavaScript. Current page url parameters will be parsed into array, that will be returned.

Monochrome Google Maps

19 Nov, 2012
This example shows how to create monocrome Google Maps. Where the map will be using only shades of grey (with or without black and/or white). It might also be called grayscale or black-and-white.

Round numbers in JavaScript

1 Oct, 2011
This snippet shows you how to round a number to a specified number of decimal places in JavaScript.

Print JavaScript object

21 Sep, 2011
This snippet shows how to print JavaScript object.

Redirection in JavaScript

16 Aug, 2011
There are many ways of doing redirect in JavaScript this should be the standard implementation for changing the current window's location.

Switching Images With Arrows in JavaScript

7 Apr, 2011
This tutorial shows how to make image switcher with javascript. You can switch images by using arrows.

Loading AJAX Page / Dynamic Content

25 Aug, 2010
Tutorial about loading page with AJAX between any HTML tags. We are using jQuery JavaScript library to do this.