Find the class of the clicked element using jquery

  • جي كويري

Find the class of the clicked element  using jquery

الأجوبة

<!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>Find  the class of the clicked element.</title>
</head>
<body>
<p>Click on the color and get the class name.</p>
<ul class="tabs">
<li class="ff0000">Red</li>
<li class="000000">Black</li>
<li class="ffd700">Gold</li>
</ul>
</body>
</html>

JavaScript Code:

$("li").click(function() {
   var colorClass = this.className;
   console.log(colorClass);
});
هل كان المحتوى مفيد؟

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

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

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