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
Articles by Shubham Vora
Page 12 of 80
How to write an inline IF statement in JavaScript?
Conditional statements are the most important and basic concept of any programming language. The if-else statement allows us to execute any code block conditionally. We can define the condition for the if statement in braces, and if the condition becomes true, it executes the code of the if block; Otherwise, it executes the code of the else block. Here, we have demonstrated how an if-else statement works in JavaScript. if (condition) { // code to execute when the condition becomes true } else { ...
Read MoreHow to write shorthand for document.getElementById() method in JavaScript?
The document.getElementById() method allows us to access any HTML element using its id in JavaScript. Every webpage can contain only a single HTML element with a single id. You can use the below example code to access any HTML element using its id: let element = document.getElementById('id'); In the above code, we used the getElementById() method of the document object and passed the id as a parameter. Now, if we require to access multiple elements using their id, it is not a good idea to repeatedly type document.getElementById(), but we can create a ...
Read MoreHow to create Covid19 Country wise status project using REST API?
Before creating the project, we will first discuss REST API. REST is a software architecture style and a collection of standards that helps make online services. Representational State Transfer is the full name of REST. Application programming interfaces (API) allow communication between two or more computer programmes. It is a software interface that gives other software programmes a service. The user must follow the rules known as a REST API based on the HTTP (Hypertext Transfer Protocol) to access web services. Conventional HTTP methods like GET, POST, PUT, and DELETE access and modify resources like data objects in a ...
Read MoreImage Transition with Fading Effect using JavaScript
Image transition means changing the image and replacing one image with another. Users can see the image transition in image sliders or galleries. While developing image sliders, we should focus on the animation for image transition to create an attractive user experience. In this tutorial, we will learn to add fading effects using various approaches to image transitions. Method 1: Adding CSS Class for Fade Effect We can use CSS to add a fading effect to image transitions. The transition property of CSS allows us to add smooth transitions to images. By adding CSS to a class ...
Read MoreImplement a JavaScript when an element loses focus
When we click on an input element in HTML, it becomes focused and displays an outline. Sometimes, we need to execute JavaScript code when the user moves focus away from an element (when it loses focus). For example, you can validate form fields when users click outside an input, showing error messages like "This field is required" if the input is empty. This is commonly used for real-time form validation. Here, we will learn different approaches to implement JavaScript when an element loses focus. Using the onblur Event Attribute The onblur event attribute triggers when an ...
Read MoreImplement polyfill for Array.prototype.reduce() method in JavaScript
The polyfill is a concept to extend the browser's features using user-defined methods. If the user's browser is not updated, it can happen that browser doesn't support the newer features of any programming language, such as JavaScript. As a developer, we require to check whether the feature is supported by the browser, and if not, we need to invoke a user-defined method. In this tutorial, we will discuss implementing the polyfill for the array.reduce() method. If any browser doesn't support the array.reduce() method, we will invoke the user-defined reduce() method. Before we start with the tutorial, let's ...
Read MoreImplement polyfill for String.prototype.trim() method in JavaScript
Some old versions of browsers don't support newly evolved JavaScript features. For example, very old browser versions don't support ES10 features like the Array.flat() method for flattening arrays. In such cases, we need to implement user-defined methods called polyfills to provide that functionality for older browsers. Here, we will implement polyfills for the String.prototype.trim() method. What is String.prototype.trim()? The trim() method removes whitespace characters from both ends of a string and returns a new string without modifying the original. Method 1: Using Regular Expression The most common approach uses a regular expression to match and ...
Read MoreHow to load the next URL in the history list in JavaScript?
In this tutorial, we will learn to load the next page in the history list in JavaScript. The Window object in JavaScript accesses the window in the browser. This object contains many properties and methods required to do the tasks. The Window object also retrieves the information from the browser window. There is a history stack in every browser that saves the pages visited by the user. To access this history stack, we can use the history object that is the property of the Window object. By accessing the history from the browser, we can go to the ...
Read MoreHow to set the color of the text-decoration with JavaScript?
In this tutorial, we will learn how to set the color of the text-decoration with JavaScript. The text-decoration is a CSS property used to decorate text lines. We can decorate a line using underline, overline, line-through, or none. To set the color of the text-decoration with JavaScript, we have multiple ways, and in this tutorial, we will discuss two of them − Using the style.textDecorationColor Property Using the style.setProperty Method Using the style.textDecorationColor Property In JavaScript, the style.textDecorationColor property of an element is used to set the color ...
Read MoreHow to convert a string into upper case using JavaScript?
In JavaScript, converting strings to uppercase is a common task needed for data validation, form processing, and ensuring consistent text formatting. JavaScript provides a built-in method for this purpose, and you can also create custom implementations to understand the underlying mechanism. This tutorial covers different approaches to convert strings to uppercase, from the standard built-in method to creating custom functions for educational purposes. Using the String toUpperCase() Method The toUpperCase() method is the most straightforward way to convert strings to uppercase. It's a built-in JavaScript method that works on any string value and returns a new string ...
Read More