How to check if a variable is a string in JavaScript

To check that a JS variable is of a type string, you can use 2 operators: instanceof and typeof. Here鈥檚 a quick solution. if (typeof text === 'string' || text instanceof String) { // it's a string!...

January 27, 2022 路 1 min 路 Coderslang Master

Get random number in a range using JavaScript

To get a random number is JS you almost always rely on the function Math.random. The only issue is that it returns a number between 0 and 1. You can generate a number in a specific range by writing a straightforward function....

January 26, 2022 路 1 min 路 Coderslang Master

How to get screen width and height with JavaScript

The object window.screen holds all the information you about the current screen. You can access the resolution of the screen by accessing its width and height properties. ...

January 25, 2022 路 1 min 路 Coderslang Master

How to check if an HTML element is visible or hidden with jQuery

There are 2 jQuery selectors that can help you determine whether an HTML element is visible or not. First, you can use the selector :visible to check if an element is visible on the web page....

January 4, 2022 路 1 min 路 Coderslang Master

How to Print an Array in JavaScript

Learn how to print the whole array with JS and how to print individual elements of the JS array in both HTML (browser) and Node.js (server-side) environments. ...

December 31, 2021 路 1 min 路 Coderslang Master

Show or Hide any HTML element with a Button Click

To toggle (show/hide) an HTML element with a button click you need to do one simple trick in the onclick handler of that button. Let me show you how it鈥檚 done. ...

December 30, 2021 路 2 min 路 Coderslang Master

HTML Vertical Line

You can add a vertical line to your HTML page by using the <div> tag with custom CSS styling. Let鈥檚 dive into the details. ...

December 29, 2021 路 1 min 路 Coderslang Master

Disable any Button with JavaScript

You can disable any HTML button with JavaScript, by setting its disabled property to true. Let鈥檚 see how you can locate a specific button and prevent clicks by disabling it. ...

December 28, 2021 路 1 min 路 Coderslang Master

How to Create a Confirmation Modal with "yes" and "no" options in JS

A JavaScript confirm function is a convenient way to display the confirmation box with the 鈥淥K鈥 and 鈥淐ancel鈥 options and capture user鈥檚 response. Let鈥檚 see how it鈥檚 done. ...

December 27, 2021 路 1 min 路 Coderslang Master

How to add a line break in HTML

You can add a line break in HTML using the <br> tag. It works in all browsers. The <br> tag is a so-called 鈥渆mpty tag鈥, which means it doesn鈥檛 need a closing tag....

December 26, 2021 路 1 min 路 Coderslang Master