HTML Articles

Page 124 of 151

What is the usage of onunload event in JavaScript?

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

The onunload event triggers when a user navigates away from a page, closes the browser tab, or refreshes the page. This event is useful for cleanup tasks like saving user data or showing farewell messages. Syntax // HTML attribute // JavaScript event listener window.addEventListener('unload', function(event) { // Cleanup code }); Example: Using onunload with HTML Attribute Close the page and see what happens! This event may give unexpected results ...

Read More

How to display the title of a document with JavaScript?

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

In JavaScript, you can display a document's title using two main approaches: the document.title property and the document.getElementsByTagName() method. This tutorial demonstrates both methods with practical examples. Using document.title Property The document.title property is the most straightforward way to access and display an HTML document's title. It directly returns the title as a string. Syntax document.title Example 1 This example shows how to display the document title by clicking a button: This is the title accessed from the document ...

Read More

What is nodeValue property in JavaScript HTML DOM?

Vikyath Ram
Vikyath Ram
Updated on 15-Mar-2026 343 Views

The nodeValue property in JavaScript HTML DOM returns the value of a node. It returns null for element nodes and the actual content for text nodes. Syntax node.nodeValue Return Value The nodeValue property returns: Text nodes: The text content Comment nodes: The comment text Element nodes: null Attribute nodes: The attribute value Example: Getting Text Node Value You can try to run the following code to learn how to get nodeValue property. ...

Read More

How to force a number to display in exponential notation?

Sravani S
Sravani S
Updated on 15-Mar-2026 1K+ Views

Use the toExponential() method to force a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation. Syntax number.toExponential(fractionDigits) Parameters fractionDigits - An optional integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number. Return Value Returns a string representing the number in exponential notation. Example: Basic Usage You can force a number to display in exponential notation as follows: ...

Read More

Which event occurs in JavaScript when an element is content is copied to clipboard?

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

When a user copies an element's content, the oncopy event triggers in JavaScript. This event fires when the user performs a copy operation using Ctrl+C, right-click copy, or any other method to copy selected content. Syntax element.oncopy = function() { // Code to execute when content is copied }; // Or using addEventListener element.addEventListener('copy', function() { // Code to execute when content is copied }); Example: Basic oncopy Event ...

Read More

How to return a string value version of the current number?

Manikanth Mani
Manikanth Mani
Updated on 15-Mar-2026 275 Views

The toLocaleString() method returns a string representation of a number formatted according to the user's locale (region and language settings). This method is useful for displaying numbers in a format familiar to users from different countries. Syntax number.toLocaleString() number.toLocaleString(locales) number.toLocaleString(locales, options) Parameters locales (optional): A string or array of strings representing locale identifiers (e.g., 'en-US', 'de-DE') options (optional): An object with formatting options like currency, minimumFractionDigits, etc. Basic Example Here's how to use toLocaleString() with different number formats: JavaScript toLocaleString() Method ...

Read More

What is the role of altKey Mouse Event in JavaScript?

Sravani S
Sravani S
Updated on 15-Mar-2026 271 Views

The altKey property of mouse events in JavaScript indicates whether the Alt key was pressed when a mouse button was clicked. This property returns a boolean value: true if the Alt key was held down, false otherwise. Syntax event.altKey Return Value Returns true if the Alt key was pressed during the mouse event, false if it was not pressed. Example The following example demonstrates how to detect whether the Alt key was pressed during a mouse click: Press and hold ALT key and ...

Read More

What records are present in JavaScript cookies?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 253 Views

Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier. Cookies are a plain text data record of 5 variable-length fields − Cookie Fields Structure Name = Value − Cookies are set and retrieved in ...

Read More

How [ ] is converted to Number in JavaScript?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 257 Views

In JavaScript, an empty array [] converts to the number 0 when using type coercion. This happens through a multi-step conversion process that JavaScript performs automatically. How the Conversion Works When converting [] to a number, JavaScript follows these steps: First, it calls the valueOf() method on the array, which returns the array itself Since the result isn't a primitive, it calls toString() on the array An empty array's toString() returns an empty string "" Finally, the empty string converts to 0 Using Number() Method ...

Read More

How to show all the options from a dropdown list with JavaScript?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 5K+ Views

To show all the options from a dropdown list, use the options property. This property allows you to access all the options and use the length property to iterate through them. Syntax // Get the select element let selectElement = document.getElementById("selectId"); // Access options selectElement.options // Returns HTMLOptionsCollection selectElement.options.length // Number of options selectElement.options[i].text // Text of option at index i selectElement.options[i].value // Value of option at index i Example: Display All Options ...

Read More
Showing 1231–1240 of 1,509 articles
« Prev 1 122 123 124 125 126 151 Next »
Advertisements