CSS Portal

HTML ondblclick Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
ondblclick
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 13th October 2023

Description

The ondblclick HTML event attribute specifies a JavaScript function to be executed when the user double-clicks on the element. It is part of the Event Attributes family, which can be used on any HTML element.

The ondblclick event fires after two click events, and by extension, after two pairs of mousedown and mouseup events. This means that the user must click on the element twice within a very short span of time in order for the ondblclick event to fire.

The ondblclick event can be used to perform a variety of actions, such as opening a new window, submitting a form, or playing a video. It is a common way to implement features such as image editing, text selection, and file dragging.

Here is an example of how to use the ondblclick event attribute:

<p ondblclick="alert('You double-clicked me!')">
  Double-click me!
</p>

When the user double-clicks on the <p> element, the alert() function will be called, displaying a message box with the text "You double-clicked me!".

Syntax

<element ondblclick="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
<html>
<head>
<title>Event attribute ondblclick</title>
</head>
<body>
<p id="demo2">Double-click on the button to run the script:</p>
<button ondblclick="mouseTest2()">Double click on me!</button>
<script>
function mouseTest2 () {
var x = document.getElementById ("demo2");
x.style.fontSize = "25px";
x.style.color = "orange";
x.style.backgroundColor = "#555555";
}
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML ondblclick event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee