Display the tag name of the clicked element using jquery

  • جي كويري

Display the tag name of the clicked element using jquery

الأجوبة

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 );
});
هل كان المحتوى مفيد؟

القوائم الدراسية التي ينتمي لها السؤال

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...