What is the dblclick() method in jQuery?

Overview

In jQuery, the dblclick() method is triggered when a selected element is double-clicked. It is a shorthand of the on('dblclick', eventHandler) method.

Syntax

$(selector).dblclick(function());

Parameters

This method takes a function, which is invoked when the dblclick() method is triggered.

Example

Explanation

In the HTML tab:

  • Line 6: We create a div content.
  • Line 7: We importe jQuery script.

In the JavaScript tab:

  • Line 4: We attach the dblclick() method on div content.
  • Line 6: We use the toggleClass() method to toggle change whenever dblclick() is invoked.

Output

When we double-click the square, the dblclick() method is invoked, and the change class is toggled. Therefore, the background color of the square is also toggled.

Free Resources