0

Basically I have a series of DIVs with varying "top" "bottom" and "padding" values. The "bottom" and "padding" I want to 0 out or eliminate, but for the "top" I need each consecutive DIV to increase by 10px, starting with 0. So basically turn something like this:

<div class="someclass" style="position:absolute;top:10px;bottom:5;padding:4;"> </div>
<div class="someclass" style="position:absolute;top:15px;bottom:10;padding:2;"> </div>
<div class="someclass" style="position:absolute;top:5px;bottom:5;padding:6;"> </div>

INTO THIS:

<div class="someclass" style="position:absolute;top:0px;bottom:0;padding:0;"> </div>
<div class="someclass" style="position:absolute;top:10px;bottom:0;padding:0;"> </div>
<div class="someclass" style="position:absolute;top:20px;bottom:0;padding:0;"> </div>

Not quite sure of the best way to zero out the other properties, but the biggest issue has been figuring out the incremental increases. Here's a fiddle I've been working with, but it only ads the +10 to all divs instead of incrementing. Fiddle

3 Answers 3

4

Maybe something like this:

$('.someclass').each(function(index, value) {
    $(this).css({
        'top': (index * 10) + 'px',
        'bottom': 0,
        'padding': 0
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

If I understand expected results properly you can use the element index to increment with:

$('.someclass').css('top', function(i, v) {
    return i*10 ;
});

DEMO

Comments

0

Try this:

 var x = document.getElementsByClassName("someClass");
 for(var i=0; i<x.length; i++){
    x[i].style.top = (i*10) + 'px';
  };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.