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
Javascript Articles
Page 319 of 534
Difference between application/x-javascript and text/javascript content types?
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 MoreWhat is the usage of onscroll event in JavaScript?
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 MoreHow to change the value of an attribute in javascript?
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 MoreWhat is the usage of onblur event in JavaScript?
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 MoreHow to output JavaScript into a Textbox?
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 MoreWhat is the usage of onfocus event in JavaScript?
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 MoreExplain JavaScript text alert
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 MoreWhat is the usage of oninput event in JavaScript?
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 MoreFlat a JavaScript array of objects into an object
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 MoreWhat is the usage of oninvalid event in JavaScript?
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