Q:

Display the tag name of the clicked element using jquery

0

Display the tag name of the clicked element using jquery

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="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>Display the tag name of the clicked element</title>
</head>
<body>
  <p></p>
  <h2>This is a heading 2</h2>
  <div>
 First name: <input type="text"><br>
 Last name: <input type="text">
</div>
</body>
</html>

JavaScript Code :

$( "*", document.body ).click(function( event ) {
  event.stopPropagation();
  var domElement = $( this ).get( 0 );
  $( "p:first" ).text( "Clicked on - " + domElement.nodeName );
});

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