Open In App

How to display a message on dblclick event on all paragraphs of a page using jQuery ?

The purpose of this article is to display a message to the double click event on all paragraphs on a page. Whenever you double-click on any of the paragraphs then the message will appear.

Used method in jQuery: 



dblclick(): This method is used to trigger the dblclick event, or attaches a function to run when a double click event occurs.

Syntax:



$(selector).dblclick(optional_function);

 

Approach:

Example:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
  
    <style>
        body {
            text-align: center;
            font-size: 30px;
        }
    </style>
  
    <script>
        $(document).ready(function () {
            $("p").dblclick(function () {
                $("#result").show().html(
                    "The paragraph was double-clicked");
            });
        });
    </script>
  
  
</head>
  
<body>
    <h2 style="color:green">GeeksforGeeks</h2>
  
    <p>
        Double-Click on this paragraph 
        to see the result.
    </p>
  
    <p>Second paragraph</p>
    <span>This is span</span>
  
    <p>Third paragraph</p>
  
    <div style="height:10px;"></div>
    <div id="result"></div>
</body>
  
</html>

Output:


Article Tags :