JSFiddle - React, Tailwind, and code Playground
by Sebastian Kay
HTML
<div id="sample">
<h3>headline 1</h3>
<h3>headline 2</h3>
<h3>headline 3</h3>
</div>
<p class="clicked"></p>
<p class="size"></p>
JavaScript
$(function(){
var size = $("#sample h3").length;
$(".size").text(size)
$("h3").on("click", function() {
var clicked = $(this).index() + 1;
var clickednext = clicked + 1;
var next = "h3:nth-child(" + clickednext + ")";
$(".clicked").text(clicked)
if (clickednext <= size){
alert($(next).html());
}else{
alert("ERROR !");
}
});
});