Q:

Find the class of the clicked element using jquery

0

Find the class of the clicked element  using jquery

All Answers

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

<!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);
});

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