I have several divs on a page. They are formatted like:
<div id='profile-1'></div>
<div id='profile-2'></div>
<div id='profile-3'></div>
<div id='profile-4'></div>
I need to find the value of the div with the highest id. In the previous example it would be “profile-4” (because 4 is the highest).
I’ve figured out how to search through the divs by using:
var elements = $('[id^=profile-]')
This returns an object. I need to take that object and figure out that “profile-4” is the highest and if possible extract the value “4”.
Any ideas?
You can do:
This will work even if you have different order eg:
In this case,
20will be alerted.