Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 293 of 652
How to convert NaN to 0 using JavaScript?
We can use the logical OR operator, double bitwise NOT operator, strict equality operator, or the isNaN() function to convert NaN to 0 using JavaScript. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. In this article, we will learn different approaches to convert NaN to 0. Using the Logical OR (||) Operator Using the Double Tilde (~~) Operator Using the Strict Equality (===) Operator Using the isNaN() function Using the Logical OR (||) Operator ...
Read MoreHow to convert special characters to HTML in Javascript?
Special characters like , and & have special meaning in HTML and can break your webpage if not properly escaped. JavaScript provides several methods to convert these characters into their HTML entity equivalents. Why Convert Special Characters to HTML? When displaying user input or dynamic content on a webpage, special characters can cause problems. For example, if you want to display "" as text, the browser might interpret it as an actual HTML tag. Converting these characters to HTML entities like ensures they display as intended text. Common characters that need escaping: ...
Read MoreHow to convert UTC date time into local date time using JavaScript?
Timezone handling is an essential component of every web application. The time that is recorded in the backend is usually in UTC format. When it is displayed to the user, however, it must be converted to the user's local time. This is possible with JavaScript. We'll look at how to use JavaScript to convert UTC date time to local date time in this blog. JavaScript Date Object JavaScript includes a "Date" object that allows us to work with dates and times. The Date object includes various methods for working with dates and times, including: ...
Read MoreHow to count text lines inside of a DOM element?
Introduction The DOM (Document Object Model) is an API for HTML and XML documents that provides programmers control over a webpage's structure, appearance, and content. Counting text lines within DOM elements is useful for layout calculations, pagination, and content management. This article explores three methods to count text lines in DOM elements using JavaScript. Method 1: Using the scrollHeight Property The scrollHeight property returns the total height of an element, including content hidden by overflow. We can calculate the number of lines by dividing scrollHeight by the height of a single line of text. ...
Read MoreHow to count the number of times a button is clicked using JavaScript?
Tracking button clicks is a common task in JavaScript and can be achieved by using the addEventListener() method. By adding an event handler to the button element and incrementing a variable each time the button is pressed, we can keep track of button clicks. We can display the count to users and even persist clicks using localStorage so they remain after browser closure. This technique is essential for interactive web applications like calculators, games, or analytics tracking. Let's explore different methods to count button clicks effectively. Creating a Basic Button First, we need a button element on ...
Read MoreHow to create 3D Geometries in webGL and p5.js?
Creating 3D geometries in WebGL and p5.js enables developers to build interactive and visually compelling web applications. With built-in functions for basic shapes, texture mapping, and transformations, both libraries provide powerful tools for 3D graphics development. Understanding WebGL vs p5.js for 3D Graphics WebGL is a low-level graphics API that provides direct access to the GPU, while p5.js offers a higher-level, artist-friendly interface. For complex 3D applications, Three.js (built on WebGL) is often preferred, whereas p5.js excels in creative coding and educational contexts. Creating Basic 3D Shapes Using Three.js (WebGL-based) Three.js simplifies WebGL by providing ...
Read MoreHow to create the previous and next buttons and non-working on the end positions using JavaScript?
We can create previous and next buttons that are disabled at their end positions using vanilla JavaScript. JavaScript allows us to control and manipulate DOM elements easily. Here, we will create navigation buttons and change an HTML element's content depending on which button is clicked. Example 1: Counter with Disabled States In this example, we will create "Next" and "Previous" buttons that increment and decrement a counter. The buttons will be disabled when they reach their extreme positions (0 for Previous and 5 for Next). Previous and Next Buttons with ...
Read MoreHow to create regular expression only accept special formula?
Regular expressions are powerful patterns used to validate and match specific text formats. In this tutorial, we'll learn how to create regular expressions that validate mathematical formulas containing various operators and formats. Basic Formula Validation Let's start with a simple regular expression that accepts basic mathematical formulas with addition and subtraction operators. Syntax let regex = /^\d+([-+]\d+)*$/g; This regex accepts formulas like "10-13+12+23" with no spaces between operators and numbers. Regular Expression Breakdown ^ – Represents the start of the string \d+ – Matches one or more digits at the ...
Read MoreHow to set cursor position in content-editable element using JavaScript?
In HTML, content editable div allows users to edit the content of the div element. We need to pass the contenteditable attribute with true Boolean value to the div element to make any div element editable. The content editable div contains the caret cursor by default, and sometimes we may require to set the caret cursor position in the content editable div element to edit the content of the div. However, we can set the caret cursor position anywhere by clicking at a particular place in the content editable div. This tutorial will teach us to use different ...
Read MoreHow to set cursor style to pointer for links without href?
We can use the tag in HTML to add a link to the web page. The default cursor style for the elements is the pointer, but removing the href attribute from the tag changes the cursor style. So, in this tutorial, we will learn to keep the cursor style to pointer for tags without the href attribute. Users can follow the example below to check out the default cursor style for the elements. Default Behavior Example In the example below, we have used the tag to create three different links. ...
Read More