I solved using a json object in which i store the elements and their position. Now i can easily change the element values:
myJsonObject = {el:[pos: 1, el: element1], el2:[pos: 2, el: element2], etc}
i have an object which is a collection of dom elements, ie:
var els = $('#myDiv div');
What i need to do is switch the position of two element contained within this object. For example: the element[2]
takes the place of element[4]
and element[4]
gets to element[2]
.
Reading through the forum i find an array prototype function to do it on arrays: Reordering arrays
but i can't use it 'cause mine is not an array. Jquery has a function to change object into arrays called makeArray
, but i must keep it as an object otherwise i cannot use all the jquery method i need later on to iterate over my object.
Has anyone any idea?