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
HTML Articles
Page 124 of 151
What is the usage of onunload event in JavaScript?
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 MoreHow to display the title of a document with JavaScript?
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 MoreWhat is nodeValue property in JavaScript HTML DOM?
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 MoreHow to force a number to display in exponential notation?
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 MoreWhich event occurs in JavaScript when an element is content is copied to clipboard?
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 MoreHow to return a string value version of the current number?
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 MoreWhat is the role of altKey Mouse Event in JavaScript?
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 MoreWhat records are present in JavaScript cookies?
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 MoreHow [ ] is converted to Number in JavaScript?
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 MoreHow to show all the options from a dropdown list with JavaScript?
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