HTML ondblclick Attribute

HTML ondblclick Attribute: This attribute is defined as it fires on a mouse double-click on the element.

HTML ondblclick Attribute

This attribute can be applied to all the HTML elements.

Syntax: <element ondblclick=”script”> 

Browser Support

The HTML ondblclick attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Internet Explorer
  • Opera
  • Safari

Example: for <button> element

<!DOCTYPE html>
<html>
<body>
<button ondblclick="myFunction()">Double-click me</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
</html>

Output:

HTML ondbclick attribute

AFTER HITTING THE DOUBLE CLICK ME BUTTON

HTML dbclick button attribute

Example: for <p> element

<!DOCTYPE html>
<html>
<body>
<p id="demo" ondblclick="myFunction()">Double-click me to change my text color.</p>
<p>A function is triggered when the p element is double-clicked.</p>
<script>
function myFunction() {
  document.getElementById("demo").style.color = "red";
}
</script>
</body>
</html>

Output: After clicking on the text. the color changes

HTML dbclick p