Found 6685 Articles for Javascript

Creating Animated Counter using HTML, CSS, and JavaScript

Mayank Agarwal
Updated on 26-Apr-2022 10:26:50

16K+ Views

In this article, we will be exploring how to create an animated counter using JavaScript and basic HTML for designing.An animated counter can be described as a display that counts an animation starting from 0 and ending at a specific number. This is generally used by popular websites for creating websites attractive and prettier.How to create animated countersWe will be using native HTML, CSS, and JavaScript for creating animated counters. Below is the approach on how to create one.We will be defining a div tag with an ID.We will add a JavaScript code to the script tag at the above div.Once ... Read More

How to Handle JavaScript Events in HTML?

Mayank Agarwal
Updated on 26-Apr-2022 10:16:07

1K+ Views

An Event is basically defined as an action or occurrence of an action that is recognized by the software. An Event can be triggered by any of the following: a user, a system, or a remote callback. Some of the popular events include pressing a button, hovering, clicking on hyperlinks, etc.In this article, we will be exploring some commonly used JavaScript events and learning how to handle these events and execute the required tasks. To handle events in HTML, we would need to add the function in the HTML tag that will be required to be executed in JavaScript when ... Read More

How to get Property Descriptors of an Object in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 10:06:02

154 Views

In this article, we are going to explore property descriptors and how we can fetch these values from an object. The Object.getOwnPropertyDescriptor method returns an object that describes the specific property from the given object. A JavaScript object can be created in multiple ways that can be called by using the property descriptors from the object.SyntaxObject.getOwnPropertyDescriptor(obj, propThe property descriptor takes two parameters as inputs that are described below −obj − The object refers to the object name whose properties need to be described.prop − It defines the specific property from the object whose value needs to be returned.This method returns ... Read More

JavaScript: How to Check if a String is a Literal or an Object?

Mayank Agarwal
Updated on 26-Apr-2022 09:59:44

2K+ Views

In this article, we will be exploring strings and how they can be used as a literal and an object depending on the requirements.JavaScript LiteralsA JavaScript literal can be referred to as representing fixed values in source code. In most languages, values are denoted by Integers, floating-point numbers, strings, boolean, characters, arrays, records, and many more.JavaScript ObjectsOn the other hand, a JavaScript object can be defined as a list of unordered primitive data types (and sometimes reference data types) that are stored as a pair with key and value. In this list, each item is defined as a property.The type ... Read More

JavaScript: How to Find Min/Max Values Without Math Functions?

Mayank Agarwal
Updated on 26-Apr-2022 08:49:27

1K+ Views

In this article, we will explore how to find the minimum and maximum values from an array without using the Math functions. Math functions including Math.min() and Math.max() returns the minimum and maximum values out of all the numbers passed in the array.ApproachWe are going to use the same functionality of the Math functions that can be implemented using a loop.This will iterate over the array elements using the for loop and will update the minimum and maximum element in a variable after comparing it with each element from the array.On finding the value greater than the max value we ... Read More

JavaScript: How to filter out Non-Unique Values from an Array?

Mayank Agarwal
Updated on 26-Apr-2022 08:43:43

1K+ Views

Arrays are data structures used to store data in a structured format. We can store the data in an array and retrieve them using their indexes. These indexes serve as a key for these values.In this article, we will filter out non-unique values and return an array that only contains unique non-repeating elements.ApproachIn an array of unique elements, we will fetch all the elements and then compare them with the set of previous elements. If any of the elements exists already, it means it’s a duplicate element and we will remove it from the resultant array.In this article, we will ... Read More

How to encode and decode a URL in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 08:32:31

6K+ Views

Encoding and decoding the URI and the URI components is required by the URL of any website to reach or redirect the user. It is a usual task in web development, and this is generally done while making a GET request to the API with the query params. The query params must also be encoded in the URL string, where the server will decode this. Many browsers automatically encode and decode the URL and the response string.E.g., A space " " is encoded as a + or %20.Encoding a URLThe conversion of the special characters can be done by using ... Read More

How to Disable Radio Buttons using JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 08:06:53

2K+ Views

A radio button is an input type that takes input in form of the options. The user will select one value from multiple choices. Only one option can be selected out of many possible choices.In this article, we will explore how to disable a radio button and how to enable it back when required. We will see how radio buttons work internally and how can we disable them when requiredMostly radio buttons are shown to the user only in some cases as part of confirmation. When not required we can disable them so that the user does not choose an ... Read More

JavaScript: How to Detect if a Website is Open on a Mobile or a Desktop?

Mayank Agarwal
Updated on 26-Apr-2022 07:56:24

8K+ Views

We can use the CSS media queries to check whether the website is opened inside a web browser or a mobile browser. This information can be fetched using the min-width and the max-width of the webpage.CSS media queries are only limited to styling the web pages but we can control the functionality of a website as per the user’s device by using the navigator properties in JavaScript.The Navigator returns a set of values that includes user browser, version, operating system, and many more.Syntaxnavigator.userAgentExampleIn the below example, we are going to use Navigator to fetch the user’s device details. This will ... Read More

How to Detect if CAPS Lock is ON using JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 07:51:22

731 Views

In this article, we are going to explore the CAPS LOCK key and how to check if they are turned on or not using JavaScript on a webpage. While working with new-age web applications, we often require certain information including user interaction and experience.The user interacts with a website to execute a functionality like hitting an API, handling clicks or buttons that trigger a method, and many more. In some of the cases, we might need to know whether the CAPS LOCK key is turned on or not.One use case can be any authentication system that notifies the user that ... Read More

Advertisements