Javascript Articles

Page 319 of 534

Difference between application/x-javascript and text/javascript content types?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

When serving JavaScript files, choosing the correct MIME type is crucial for proper browser handling. Let's explore the differences between these content types and understand which one to use. text/javascript (Obsolete) The text/javascript content type was used in the early days of HTML but is now obsolete according to RFC 4329. While browsers still support it for backward compatibility, it should not be used in modern applications. // Server header (obsolete) Content-Type: text/javascript application/x-javascript (Experimental) application/x-javascript was an experimental content type, indicated by the "x-" prefix. The "x-" denotes non-standard or experimental MIME ...

Read More

What is the usage of onscroll event in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 246 Views

The onscroll event in JavaScript occurs when an element's scrollbar is being scrolled. This event is commonly used to create interactive features like scroll-triggered animations, infinite scrolling, or scroll position indicators. Syntax element.onscroll = function() { // Code to execute when scrolling }; // Or using addEventListener element.addEventListener('scroll', function() { // Code to execute when scrolling }); Basic Example Here's a simple example showing how to detect when a div element is scrolled: ...

Read More

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

What is the usage of onblur event in JavaScript?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 953 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

How to output JavaScript into a Textbox?

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

You can output JavaScript values to a textbox using the value property. This is commonly done to display calculation results or user feedback. Basic Approach To output to a textbox, access the input element and set its value property: document.getElementById("myTextbox").value = "Your output here"; Example: Calculator with Textbox Output JavaScript Textbox Output First Number: ...

Read More

What is the usage of onfocus event in JavaScript?

Govinda Sai
Govinda Sai
Updated on 15-Mar-2026 654 Views

The onfocus event is triggered when an HTML element receives focus, typically when a user clicks on an input field or navigates to it using the Tab key. This event is commonly used to provide visual feedback or perform actions when users interact with form elements. Syntax // HTML attribute // JavaScript event listener element.onfocus = function() { /* code */ }; element.addEventListener('focus', function() { /* code */ }); Example: Basic onfocus Implementation Click on the input field to see the onfocus effect: ...

Read More

Explain JavaScript text alert

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

The JavaScript alert() function is used to display a popup message to the user. It's a built-in browser method that creates a modal dialog box with a message and an "OK" button. Syntax alert(message); Parameters The alert() function accepts one parameter: message - A string that specifies the text to display in the alert box Basic Example JavaScript Alert Example JavaScript Text ...

Read More

What is the usage of oninput event in JavaScript?

Sai Nath
Sai Nath
Updated on 15-Mar-2026 436 Views

The oninput event occurs whenever the value of an input element changes. Unlike onchange, which fires only when the element loses focus, oninput triggers immediately as the user types, making it ideal for real-time validation and live search functionality. Syntax // HTML attribute // JavaScript property element.oninput = function() { /* code */ }; // Event listener element.addEventListener('input', function() { /* code */ }); Basic Example oninput Example Type something below: ...

Read More

Flat a JavaScript array of objects into an object

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

To flatten a JavaScript array of objects into a single object, we can create a function that iterates through each object in the array and combines their properties. This technique is useful when you need to merge multiple objects while preserving unique property names by appending indices. Basic Approach The most straightforward method is to loop through the array and create new property names by appending the array index to each original property name. // Example array of objects const notes = [{ title: 'Hello world', id: 1 ...

Read More

What is the usage of oninvalid event in JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 333 Views

The oninvalid event is triggered when a form field fails HTML5 validation constraints. It fires before form submission when an field with validation attributes (like required, pattern, etc.) contains invalid data. Syntax element.oninvalid = function() { // Handle invalid input }; // Or in HTML Basic Example Here's how to use oninvalid to show custom validation messages: Enter Name: ...

Read More
Showing 3181–3190 of 5,340 articles
« Prev 1 317 318 319 320 321 534 Next »
Advertisements