I have a jQuery id like
<div id="myid-page-top-0">
some stuff
</div>
I want to use jQuery to grab the "0"
from the end of the #id
. I have tried like
$('div').slice(-1,0);
But this doesn't work ? Any ideas ?
I have a jQuery id like
<div id="myid-page-top-0">
some stuff
</div>
I want to use jQuery to grab the "0"
from the end of the #id
. I have tried like
$('div').slice(-1,0);
But this doesn't work ? Any ideas ?
Here you go buddy. Tested and working. iterates through all divs and returns the ending number
$('div')
is an object, you want the ID:If your numbers go into double digits though you might run into problems, it might be better to do it like this:
Instead of slice, which would only work if your id contains numbers 0-9, not if it is say 10 or 11, you should base it off of the dashes.
Something like:
or in your code something like: