I would like to get the text() values of every span. Best case scenario would involve a solution that makes use of the "event"-parameter.
$(document).ready(function () {
$('li').click(function (e) {
console.log($("span:nth-of-type(1n)").text());
console.log($("span:nth-of-type(2n)").text());
console.log($("span:nth-of-type(3n)").text());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ul>
<li>
<span>li1 + span1</span>
<span>li1 + span2</span>
<span>li1 + span3</span>
</li>
<li>
<span>li2 + span1</span>
<span>li2 + span2</span>
<span>li3 + span3</span>
</li>
</ul>
</div>
If you have any idea, I would highly appreciate a working snippet.
The expected output would be something like:
let var1 = $("span:nth-of-type(1n)").text(); // li1 + span1
let var2 = $("span:nth-of-type(2n)").text(); // li1 + span2
let var3 = $("span:nth-of-type(3n)").text(); // li1 + span3
In the forEach-loop solution, I would need the span's text element in every loop, which I don't have.