Articles on Trending Technologies

Technical articles with clear explanations and examples

How to find out what character key is pressed in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 745 Views

To find out which character key is pressed in JavaScript, you can use various methods. The modern approach uses the key property, while legacy methods relied on keyCode. Modern Approach: Using event.key The key property directly returns the character that was pressed, making it the preferred method: Key Detection - Modern Method Type in the input field below: ...

Read More

From a list of IDs with empty and non-empty values, retrieve specific ID records in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 292 Views

When working with arrays of objects containing IDs, you often need to filter records based on specific ID values. JavaScript's filter() method provides an efficient way to retrieve all objects matching a particular ID, even when the array contains empty or null ID values. Sample Data Let's work with the following array that contains both valid and empty ID values: var details = [ {id: 101, name: "John", age: 21}, {id: 111, name: "David", age: 24}, {id: 1, name: "Mike", age: 22}, ...

Read More

JavaScript - Find the smallest n digit number or greater

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 448 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n digit number which is a multiple of all the elements specified in the array. If there exist no such n digit element then we should return the smallest such element. For example: If the array is: const arr = [12, 4, 5, 10, 9] For both n = 2 and n = 3, the output should be 180 Example Following ...

Read More

What is the difference between void, eval, and the Function constructor in JavaScript?

usharani
usharani
Updated on 15-Mar-2026 462 Views

JavaScript provides three distinct features for executing and manipulating code: void, eval(), and the Function constructor. Each serves different purposes and has unique characteristics. The void Operator The void operator evaluates an expression and always returns undefined. It's commonly used to prevent unwanted return values or create undefined values explicitly. Syntax void expression void(expression) Example // Basic void usage console.log(void 0); ...

Read More

How to get the value of the id attribute a link in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 10K+ Views

In this tutorial, we will learn how to get the value of the id attribute of a link in JavaScript. The id attribute stores a unique value for an HTML element. The id of an element must be unique, and no other elements should have the same id. The id attribute of a link can be retrieved in different ways, and in this tutorial, we will discuss the most popular methods: Using document.getElementById() method Using document.getElementsByTagName() method Using document.querySelectorAll() method Using document.getElementById() Method The ...

Read More

How to add many Event Handlers to the same element with JavaScript HTML DOM?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 13K+ Views

When building interactive web applications, you often need to handle multiple events on the same element. For example, a button might respond to both clicks and hover events. JavaScript provides several approaches to attach multiple event listeners to a single DOM element efficiently. Using Multiple addEventListener Methods Using Array.forEach() for Event Registration Using Multiple addEventListener Methods The addEventListener method is the standard way to attach event handlers in JavaScript. You can call it multiple times on the same element to register different event types, each with their ...

Read More

How to display HTML5 client-side validation error bubbles?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 421 Views

HTML5 provides built-in client-side validation with error bubbles that appear when users try to submit invalid form data. The required attribute and input types like email automatically trigger these validation messages. Basic Required Field Validation The required attribute prevents form submission if the field is empty and displays a validation bubble: HTML5 Validation Enter Email: ...

Read More

Change the color of the left border with CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 232 Views

The border-left-color property in CSS allows you to change the color of an element's left border independently from other borders. This property is useful when you want to create visual emphasis or design accents on specific sides of an element. Syntax border-left-color: color-value; Parameters The property accepts various color values: Color names: red, blue, green, etc. Hex values: #FF0000, #00FF00, etc. RGB values: rgb(255, 0, 0) HSL values: hsl(0, 100%, 50%) Example p.demo { ...

Read More

Order an array of words based on another array of words JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 433 Views

When working with arrays in JavaScript, you may need to reorder an array of objects based on the order specified in another array. This is useful for sorting data according to custom priorities or sequences. Let's say we have an array of objects sorted by their id property: const unordered = [{ id: 1, string: 'sometimes' }, { id: 2, string: 'be' }, { id: 3, string: 'can' }, { ...

Read More

Simplest way to detect keypresses in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 365 Views

The simplest way to detect keypresses in JavaScript is using the onkeypress event handler. However, modern JavaScript also provides addEventListener for better event handling. document.onkeypress The key press is matched with the keyCode property, which returns the Unicode character code of the key that triggered the onkeypress event. Using document.onkeypress Keypress Detection Press any key to see the detection in action! ...

Read More
Showing 17411–17420 of 61,297 articles
Advertisements