2
I have an html structure like this:
<div id="container1">
<p>Texto</p>
</div>
<div id="container2">
<p>Texto</p>
</div> N vezes este bloco
<div id="containerN">
<p>Texto</p>
</div>
I wonder how I get the last one id="containerN"
, separate the number that equals the N
and put into a variable. For example, if the latter is the ID="container22"
I want to put in the variable cont=22
.
$('.container').last()
does not guarantee that the largest number will return, in case the DOM is mixed. (Still+1
by the idea, which could also bedata-id
instead of ID.)– Sergio
Correct @Sergio, I assumed that the Divs would be in order, data-id is also a good.
– Nicolas Pio