JSFiddle - React, Tailwind, and code Playground
HTML
<div class="shikhar">
<div class="a">Superman</div>
<div class="b">Hulk</div>
</div>
<div class="shikhar">
<div class="a">Spiderman</div>
<div class="b">Batman</div>
</div>
CSS
.selected {
color:red;
}
.highlight {
background:yellow;
}
JavaScript
$(document).ready(function () {
$('.shikhar').click(function (e) {
var decide = $(e.target).attr('class');
//here I want to know what was the class of the element that was clicked
alert(decide);
if (decide == 'a') {
$(this).find('.b').addClass("selected");
$(this).find('.a').addClass("highlight");
} else {
$(this).find('.a').addClass("selected");
$(this).find('.b').addClass("highlight");
}
});
});