Damathryx
Damathryx

Reputation: 2828

Top is not working

Heres the code:

$('> li', this).each(function (index) {
    var top_space = $(this).css('padding-top');
    $(this).prepend('<div></div>');
    $('> div', this).css({
        position: "absolute",
        top: -top_space,
        width: "100%",
        height: top_space,
            "z-index": 0
    });
});

Here's the result in inspect element:


enter image description here


As you can see there is no top attribute, but when I remove the negative sign...


enter image description here


There's a top attribute but not working, it's still in top:0


enter image description here


I've been stuck for almost an hour now, can't figure out why. What am I missing?

Upvotes: 2

Views: 70

Answers (3)

prakashstar42
prakashstar42

Reputation: 687

Your top_space will be string so you can't make it like "-top_space"

Try: -(parseInt(top_space))

Upvotes: 1

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Use concatenation + operator

top:  "-" + top_space

Demo

Upvotes: 2

Subha
Subha

Reputation: 1051

Try this -

top: "-" + top_space,

Upvotes: 2

Related Questions