I have a class in jQuery, I want to get the class of the element that has been clicked. (The element is in the same Class).
<!DOCTYPE html>
<html>
<head>
<title>Try jQuery 2.0.0 Online</title>
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script>
$(document).ready(function() {
$('.shikhar').click(function(){
var decide=$(this).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");
}
});
});
</script>
<style>
.selected {
color:red;
}
.highlight {
background:yellow;
}
</style>
</head>
<body>
<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>
</body>
</html>
Heres a fiddle - http://jsfiddle.net/6QjN6/