i have a short question:
I have multiple elements with the same class, and i want to alert dynamically the data-index value of the the element with the style "display: block".
Here is my code:
var test = $('.test').data('index');
alert( test );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="test" style="display:none" data-index="0" href="#">foo!</a>
<a class="test" style="display:block" data-index="1" href="#">foo!</a>
<a class="test" style="display:none" data-index="2" href="#">foo!</a>
:visible can be used just like in CSS for this purpose
var test = $('.test:visible').data('index');
alert( test );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="test" style="display:none" data-index="0" href="#">foo!</a>
<a class="test" style="display:block" data-index="1" href="#">foo!</a>
<a class="test" style="display:none" data-index="2" href="#">foo!</a>