Q:

Change elements top position with jQuery

I have a page with several  elements. 
They are absolutely positioned, each has css attribute "top".
I want to go through all of the elements and change their top position by 20px.
So it means I need to get current top position and add 20px to it.
The number of  elements is unknown as it can change at any time.
Thanks!

A:

You can use the += syntax that animate also supports

 $('.box1').css('top','+=20px');
.box {
    width: 100px; height:100px; position: absolute; top: 10px;
}

.box1 { background-color: red; left:10px; }
.box2 { background-color: yellow; left: 120px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box box1"></div>
<div class="box box2"></div>

A:

Gather the elements
var $elements = $("div");

Then iterate through each one of them and add the required
$elements.each(function () {
    $(this).css({top: "+=20px"});
})

