Q:

Demonstrate how to handle click and double-click on a paragraph. Note: As the coordinates are window relative, so in this case relative to the demo iframe using jquery

0

Demonstrate how to handle click and double-click on a paragraph.  using jquery

Note: As the coordinates are window relative, so in this case relative to the demo iframe.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Demonstrate how to handle click and double-click on a paragraph.</title>
</head>
<body>
<p>Click or double click here.</p>
 <p id="result"></p>
 </body>
</html>

JavaScript Code :

$("p").bind( "click", function( event ) {
  var str = "( " + event.pageX + ", " + event.pageY + " )";
  $( "#result" ).text( "Click happened! " + str );
});
$( "p" ).bind( "dblclick", function() {
  $( "#result" ).text( "Double-click happened");
});
$( "#result" ).bind( "mouseenter mouseleave", function( event ) {
  $( this ).toggleClass( "over" );
});

Used Methods :

  • .toggleClass() : Add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the state argument.
  • .bind() : Attach a handler to an event for the elements.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now