JQuery: How to reset all positions of elements on a page?

Let's say I have a bunch of DIVs with class "apple" and another group of DIVs with class "orange".

These DIVs all have different positions, but I want to use a jQuery function to assign them new positions relative to their parent containers living on the page, without reloading.

So, for example, how can I set all DIVs with class "apple" to "top" value "200px" relative to the parent container without reloading the page?

Thanks!

+2


a source to share


1 answer


var $apples = $('.apple'); // caching your elements

$apples.parent().css('position', 'relative'); // setting the parent to a relative position

$apples.css('position', 'absolute')  // setting an absolute position, relative to the parent
       .css('top', '200px');  // setting the top position

      



+3


a source







All Articles