I have an array with objects id’s:
one
two
there
etc..
And i have quite a long object list:
<div id="container">
<input type="text" id="one" />
<input type="text" id="two" />
<input type="text" id="three" />
</div>
This is not the actual html code, just a simplified version.
Now my array with id’s keeps changing, and my question would be
how can i find out which element from that array is the first element in #container div
For example if i have this order:
{
email
name
date
}
And this list of html objects
<div id="container">
<input type="text" id="name" />
<input type="text" id="last_name" />
<input type="text" id="email" />
<input type="text" id="date" />
</div>
name would be first, but in that array in some cases name item won’t exist so it won’t always be the name, i hope this makes any sense 🙂
If you want to sync your array order with the document order, you could do this:
JS:
http://jsfiddle.net/KKz9U/1/
The
$.uniquesorts the elements to the same order as they are in the document