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
Web Development Articles
Page 125 of 801
How to check if a string is html or not using JavaScript?
When working with dynamic HTML content in JavaScript, it's crucial to validate HTML strings before inserting them into the DOM. Invalid HTML can break your webpage structure or cause rendering issues. This article explores two reliable methods to check if a string contains valid HTML using JavaScript. Using Regular Expression to Validate HTML Regular expressions provide a powerful way to match HTML patterns. We can create a regex pattern that identifies valid HTML tags with proper opening and closing structure. Syntax let regexForHTML = /]*>(.*?)/; let isValid = regexForHTML.test(string); Regex Pattern Explanation ...
Read MoreHow to check if the date is less than 1 hour ago using JavaScript?
In this tutorial, we will learn to find the difference between two dates and check if the difference is less than one hour. Sometimes, developers must play with the Date object and perform some operation every hour. So, this can be one approach that checks if a particular operation is performed before an hour, perform it again; otherwise, wait to complete the hour. Here, we will learn different approaches to check if the date is less than 1 hour ago using JavaScript. Use the getTime() method The getTime() method returns the total milliseconds for the date from ...
Read MoreHow to check if one date is between two dates in JavaScript?
In JavaScript, we can use the Date() object to create different timestamps. Also, we may be required to check if one date is between two using JavaScript. For example, we want to create a filter for orders in the eCommerce application based on the dates. So, we should be able to filter all orders between the two dates that users enter into the date input field. Another real-world use case of checking one date between two is in the banking application. For example, while developing the banking system application, developers need to create a filter allowing users to ...
Read MoreHow to check if the clicked element is a div or not in JavaScript?
When building interactive web applications, you often need to detect clicks on specific elements like divs. This is particularly useful for modals, dropdowns, or any clickable containers. This tutorial explores three effective methods to check if a clicked element is a div. Using the onClick Attribute The onClick attribute is the simplest way to detect clicks on a specific div element. You assign a function that executes when the div is clicked. Syntax This is a div! function clickFunction() { // perform operation on click ...
Read MoreHow to check input file is empty or not using JavaScript/jQuery?
In JavaScript, while working with the form elements, we need to validate the input fields and form elements when a user enters the value. In this tutorial, we will work with the file input. We will also learn to validate the file input. Sometimes, we may be required to check if the file is selected in the input field, then only enable the submit button; otherwise, disable the submit button. So, it will not allow users to submit the form or file without selecting it. Validate the file input using JavaScript In JavaScript, we can access the ...
Read MoreGet the relative timestamp difference between dates in JavaScript
Have you ever seen notifications on any website showing the time stamp? It shows something like "12 minutes ago", "2 days ago", "10 hours ago", etc. It is related to the timestamp difference between two dates or times. Also, some apps show that this device's last login was 22 hours ago. So, there are many uses to get the timestamp difference between two dates. In this tutorial, we will learn different approaches to get the relative timestamp difference between two dates. Using getTime() Method with Custom Algorithm In JavaScript, we can create a date object using ...
Read MoreJavaScript Program to Count rotations required to sort given array in non-increasing order
We will be writing a program to count the number of rotations required to sort an array in non-increasing order. A rotation moves the first element to the end of the array. The program identifies where the array starts to break the non-increasing pattern and calculates the minimum rotations needed. Understanding the Problem For an array to be sorted in non-increasing order, each element should be greater than or equal to the next element. If we have a rotated sorted array, we need to find the rotation point and calculate how many positions we need to rotate to ...
Read MoreJavaScript Program To Delete Alternate Nodes Of A Linked List
We will be writing a JavaScript program to delete alternate nodes of a linked list. We will be utilizing a while loop to traverse the linked list while keeping track of the current node. In each iteration, we will skip every second node by linking the current node directly to the node after the next one, effectively removing alternate nodes from the list. Approach Start traversing from the head node of the linked list. For each node, check if both current node and its next node exist. Skip ...
Read MoreJavaScript Program To Delete Nodes Which Have A Greater Value On Right Side
We will implement a function to delete nodes in a linked list which have a greater value on their right side. The approach is to traverse the linked list from right to left and keep track of the maximum value encountered so far. For each node, we compare its value with the maximum value and delete the node if its value is less than the maximum value. Problem Understanding Given a singly linked list, we need to delete all nodes that have at least one node with a greater value to their right. For example, in the list ...
Read MoreJavaScript Program to Find a triplet such that sum of two equals to third element
We will be writing a JavaScript program that finds a triplet where the sum of two elements equals the third element. This program will be implemented using arrays and loop structures. We will iterate through the array and check for each combination of three elements if two elements sum up to the third. If we find such a triplet, we will return it immediately. Problem Understanding Given an array, we need to find three elements (a triplet) where a + b = c. For example, in array [1, 4, 45, 6, 10, 8], the triplet [4, 6, 10] ...
Read More