Articles on Trending Technologies

Technical articles with clear explanations and examples

How to change the value of an attribute in javascript?

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

In JavaScript, changing attribute values dynamically allows you to create interactive web pages. Whether you need to modify styles, swap images, or update element properties, JavaScript provides several methods to manipulate HTML attributes. To change an attribute value, you first need to access the HTML element using methods like getElementById(), then modify the attribute directly or use methods like setAttribute(). Syntax Here are the main approaches to change attribute values: // Direct property access element.attribute = new_value; // Using setAttribute method element.setAttribute("attribute", "value"); Parameters attribute − The name of the ...

Read More

How to listen to Keydown-Events in a KineticJS-managed HTML5-Canvas?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 182 Views

To listen to keydown events in a KineticJS-managed HTML5 canvas, you need to make the canvas focusable and attach event listeners. KineticJS canvases don't receive keyboard events by default since they're not focusable elements. Making the Canvas Focusable First, get the canvas element and make it focusable by setting the tabindex attribute: // Create KineticJS stage and layer ...

Read More

What is the usage of and elements? Why they were introduced?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 189 Views

The HTML5 and elements are semantic tags that provide meaningful structure to web content. They improve accessibility for screen readers and help visually impaired users navigate content more effectively. These elements are also beneficial for eBook readers and search engines. The Element The element represents a thematic grouping of content, typically with its own heading. It's used to divide content into distinct sections within a document. Syntax Section Title Section content goes here... Example ...

Read More

Loop through a Set using Javascript

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

In JavaScript, you can loop through a Set using several methods. The most common approaches are using the forEach() method, for...of loop, or converting to an array. Using forEach() Method The forEach() method executes a provided function for each value in the Set: const mySet = new Set([1, 2, 5, 8]); mySet.forEach(value => { console.log(`Element is ${value}`); }); Element is 1 Element is 2 Element is 5 Element is 8 Using for...of Loop The for...of loop provides a cleaner syntax for iterating over Set values: ...

Read More

JavaScript – Getting Coordinates of mouse

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 536 Views

In JavaScript, you can get the coordinates of the mouse cursor using mouse event properties. The most common approach is to use the mousemove event listener along with event properties like clientX, clientY, pageX, and pageY. Mouse Coordinate Properties Different properties provide coordinates relative to different reference points: clientX, clientY - Coordinates relative to the viewport (visible browser window) pageX, pageY - Coordinates relative to the entire document (includes scrolled areas) screenX, screenY - Coordinates relative to the user's screen offsetX, offsetY - Coordinates ...

Read More

Object de-structuring in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 169 Views

Object destructuring is a JavaScript feature that allows you to extract multiple properties from an object and assign them to variables in a single statement. It provides a clean and concise way to work with object properties. Syntax const { property1, property2, property3 } = object; Basic Example Object Destructuring Object Destructuring Example ...

Read More

Sorting JavaScript object by length of array properties.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 546 Views

In JavaScript, you can sort objects by the length of their array properties using the sort() method with a custom comparison function. This is useful when organizing data based on array sizes. Syntax array.sort((a, b) => a.property.length - b.property.length); Example: Sorting Students by Number of Subjects Sort by Array Length body { ...

Read More

How to get odd and even position characters from a string?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you can extract characters from odd and even positions in a string using various methods. This technique is useful for string manipulation tasks like creating puzzles, encoding, or data processing. Understanding the Problem Given a string, we want to separate characters based on their position index: Even positions (0, 2, 4...): "T", "i", " ", "s", " ", "a", " ", "e", "t", "!" Odd positions (1, 3, 5...): "h", "s", "i", "", "i", "", "t", "s", "" If the string is "This is a test!" Even positions: "Ti s a ...

Read More

Getting equal or greater than number from the list of numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 852 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument. Example Following is the code − const arr = [56, 34, 2, 7, 76, 4, 45, 3, 3, 34, 23, 2, 56, 5]; const threshold = 40; const findGreater = (arr, num) => { const res = ...

Read More

What is the usage of onblur event in JavaScript?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 961 Views

The onblur event in JavaScript triggers when an HTML element loses focus. This commonly occurs when users click away from an input field, tab to another element, or programmatically change focus. Syntax // OR element.onblur = function() { /* code */ }; // OR element.addEventListener('blur', function() { /* code */ }); Example: Input Field Validation Enter your email and click outside the field: ...

Read More
Showing 17901–17910 of 61,297 articles
Advertisements