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 84 of 151
How do we include the legal number intervals for an input field in HTML?
The step attribute in HTML defines the legal number intervals for input fields. It specifies the increment value that users can select, creating a controlled range of acceptable values. The step attribute works with numeric input types like number, range, date, datetime-local, month, time, and week. Syntax Following is the syntax for the step attribute − The value can be a positive number, decimal, or the keyword any. When combined with min and max attributes, it creates a complete range validation system. Step Attribute with Number Input The step attribute controls ...
Read MoreExecute a script when the document is about to be unloaded in HTML?
The onbeforeunload event attribute in HTML fires when the document is about to be unloaded, such as when a user closes the browser tab, navigates away from the page, or refreshes it. This event is commonly used to warn users about unsaved changes or to perform cleanup operations before the page is destroyed. Syntax Following is the syntax for the onbeforeunload event attribute − The event handler function can return a string message that will be displayed in the browser's confirmation dialog. However, modern browsers may show their own generic message instead of ...
Read MoreExecute a script when there have been changes to the anchor part of the URL in HTML?
The onhashchange event in HTML executes a script whenever the anchor part (hash fragment) of the URL changes. The anchor part refers to the portion of the URL that comes after the # symbol, commonly used for navigation within a page or single-page applications. This event is particularly useful for detecting when users navigate using the browser's back/forward buttons or when the URL hash is programmatically modified. The hash change can be detected using either the onhashchange attribute or JavaScript event listeners. Syntax Following is the syntax for the onhashchange attribute − ...
Read MoreHow do we set the type of element in HTML?
In HTML, the type attribute is used to specify the type or behavior of various HTML elements. This attribute is essential for defining how elements should function and what kind of content they handle. The type attribute is commonly used with form elements like and , as well as multimedia and resource elements. The type attribute serves different purposes depending on the element − Form elements − Defines the input type or button behavior Script elements − Specifies the scripting language or MIME type Media elements − Indicates the media format or MIME type Link elements ...
Read MoreExecute a script when a file can be played all the way to the end without pausing for buffering in HTML?
The oncanplaythrough attribute in HTML5 executes a JavaScript function when a media file (audio or video) can be played all the way through without pausing for buffering. This event fires when the browser estimates that enough data has been loaded to play the media from start to finish at the current playback rate. Syntax Following is the syntax for the oncanplaythrough attribute − The functionName() is a JavaScript function that gets executed when the media can play through without buffering interruptions. How It Works The oncanplaythrough event is part of ...
Read MoreHow to add the value of the element in HTML?
The value attribute in HTML specifies the initial or default value for various form elements. It serves different purposes depending on the element type − from setting default text in input fields to defining the data sent when buttons are clicked. Understanding how to properly use the value attribute is essential for creating functional HTML forms. Syntax Following is the basic syntax for using the value attribute − The value attribute can be used with the following HTML elements − − Sets default value for form inputs − Defines ...
Read MoreExecute a script after the document is printed in HTML?
The onafterprint event attribute in HTML executes a JavaScript function after the user has printed the document or closed the print preview dialog. This event is useful for tracking print actions, cleaning up resources, or providing user feedback after printing. Syntax Following is the syntax for the onafterprint attribute − You can also use it with JavaScript event listeners − window.addEventListener("afterprint", functionName); Using onafterprint Attribute The onafterprint attribute is typically added to the element and triggers when the print dialog is closed, regardless of whether the user ...
Read MoreExecute a script when a context menu is triggered in HTML5?
The contextmenu attribute in HTML5 allows you to execute a script when a context menu is triggered. A context menu appears when a user right-clicks on an element. This attribute links an element to a custom element that defines the context menu options. Syntax Following is the syntax for the contextmenu attribute − Content The contextmenu attribute value must match the id of a element with type="context". Basic Context Menu Example Following example demonstrates how to create a basic context ...
Read MoreExecute a script when the element is being clicked in HTML?
Use the onclick attribute to execute a script when an element is clicked in HTML. The onclick attribute allows you to run JavaScript functions directly when a user interacts with elements like buttons, links, divs, or any clickable HTML element. Syntax Following is the syntax for the onclick attribute − Content You can also execute JavaScript code directly within the onclick attribute − Content Using onclick with Button Elements Example − Basic onclick Function Following example demonstrates how to use the onclick attribute to execute a JavaScript function ...
Read MoreHow to specify the URL of the page the link goes to in HTML?
The href attribute in HTML is used to specify the URL of the page that a link should navigate to. The href attribute is primarily used with the (anchor) tag to create hyperlinks that allow users to navigate between web pages or different sections within the same page. Syntax Following is the syntax for using the href attribute with anchor tags − Link Text The URL can be an absolute URL, relative URL, or an anchor link to a section within the same page. Types of URLs in href Attribute The ...
Read More