Css selector for element which have numbers as class name.

Learn how to select the element which has the class name starting with number. HTML5 supports numbers as id and class name , but css selector have some rules , A valid name should start with a letter (a-z)[A-Z] , an underscore (_), or a hyphen (-) which is followed by any numbers, hyphens, underscores, letters. A name …

Remove All children 👶 of the node in Javascript.

Learn how to delete all the nodes inside a div or any node in Javascript. You can do it in three ways 1 . Set the node innerHTML as empty-string(“”). var node = document.getElementById(‘parent’); node.innerHTML = “”; This method removes all the text and nodes inside the parent node. If you need to delete only the …

Understanding weirdness of the “!” bang operator in JavaScript

There are some things we don’t know about how the ! operator works in Javascript. Basics The ! is a logical operator that will convert a value to its opposite boolean. Since JavaScript will coerce values, it will “convert” a value to its truthy/falsey form and return the opposite boolean value. When we perform the ! operation on …

Getting max of numbers in Javascript.

Learn how to get the maximum of numbers. max function in the Math object can be used to find the maximum of multiple numbers and array. Math.max(1,2); //2 Math.max(1,2,3); //3 If any one of the argument passed cannot be converted to number then it returns NaN Math.max(‘1’, 0); //1 Math.max(‘one’, 1); // NaN Math.max(1, 2, …

Flatten an array in javascript

Learn how to convert a multi-dimensional array into single dimension array in javascript We can flatten an array to single dimension array using Array.flat(depth) method. But if we have multi-dimensional array then we need to find the depth of the Array, instead of finding depth we can solve the problem in two ways we can …

Removing space in string in Javascript

Learn how to remove space in string. If you want to remove all the space in the string then , you can use replace method var name = “Javascript jeep “; name.replace(/s/g,”); // Javascriptjeep s –> spaceg –> replace globally We can also replace the space with ‘-‘ var name = “Javascript jeep “; name.replace(/s/g,’-‘); // …

Misunderstanding on parsing Boolean

Learn about how to parse boolean in Javascript. Creating a boolean value using Boolean constructor var b = new Boolean(); b is an object which have the value false in it. But the problem here is most of the beginner think as we can use directly in if , but it results to misunderstanding if(b) { …

How to convert 24 hours format to 12 hours in Javascript.

Convert the 24 hours format time to 12 hours formatted time. You can get the time by , var dt = new Date(); var hours = dt.getHours(); // gives the value in 24 hours format var minutes = dt.getMinutes() ; var finalTime = “Time – ” + hours + “:” + minutes; finalTime // final time …

Creating a simple loader only using CSS

Loader are the impressing part of the website , which needs to be simple and fun , So we will build an elegant loader . This loader is inspired from here. Create a container which is going to hold the loader <html> <body> <div class=”container”> </div> </body> </html> Set the width and height of the body to 100% , …

Difference between String primitives and String object.

Learn about, in what way the string primitive and string objects are different in javascript. We can create string in three ways, 1. var a = “first way”; // we can also use single quotes 2. var b = String(“second way”); 3. var c = new String(“third way”); // also we can create using 4. …

Design a site like this with WordPress.com
Get started