1
How can I use the index()
just to know the location of the element between elements that share the same specific class? For example, I want index() to ignore all other classes except the class x
:
<div class="y"></div>
<div class="x"></div>
<div class="z"></div>
<div class="x index"></div>
<div class="y"></div>
<div class="x"></div>
<div class="z"></div>
In the script:
console.log($(".index").index()); // resultado 3
In this case, I want him to just count as if there were only class elemetos x
<!--<div class="y"></div> ignorado -->
<div class="x"></div>
<!--<div class="z"></div> ignorado -->
<div class="x index"></div>
<!--<div class="y"></div> ignorado -->
<div class="x"></div>
<!--<div class="z"></div> ignorado -->
In the script:
console.log($(".index").index()); // resultado 1
But you already have this in the example you made, when you make $(".index"), you select this element, now is to know what you want to do with this selection.
– Wictor Chaves
Are you wanting to get the other classes of the element? Explain your question better.
– GustavoAdolfo
In case index() will count the location using all elements, I want it to count only with class x elements, in the example above it will point 3 (starts at 0), but I want it to point 1 because it comes an element of it before with class 'x', instead of having all the elements, count only with the class elements x
– João Victor
I understand what you want, but what’s the point?
– Wictor Chaves
I am creating a slide system in a cloud project for my TCC, I have the problem just in this function to count the current image being seen, like: "image 5 of 10"
– João Victor