Is there a way to get the index of the clicked element within its list as well as in its .blue
class?
I have successfully obtained the index within its list, but I am struggling to figure out how to get the index within its .blue
class. For instance, when clicking on the 5th button, I want it to display 'index 4 - class index 3'.
Any suggestions or solutions?
$('.showindex').click(function() {
var index = $(this).closest("li").index();
console.log("index " + index + " - class index " + "?");
});
.blue {
color: blue;
}
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<ol id="ol1">
<li><input type="button" value="Show index" class="showindex blue">showindex blue</li>
<li><input type="button" value="Show index" class="showindex">showindex</li>
<li><input type="button" value="Show index" class="showindex blue">showindex blue</li>
<li><input type="button" value="Show index" class="showindex">showindex</li>
<li><input type="button" value="Show index" class="showindex blue">showindex blue</li>
</ol>