Lukas
Lukas

Reputation: 7734

How to detect margin-left of element with jQuery

Wird, I thought this is obvious but not necessarily, can anybody tell me how to detect margin with jQuery? I have this and in console i have good result but it's not working on page:

var margin_left = circle.css('margin-left').toLowerCase();
circles_container.css('margin-left', -margin_left + 'px');

Much thx for help.

Upvotes: 0

Views: 316

Answers (4)

Rohit Agrawal
Rohit Agrawal

Reputation: 5490

Try this -

var marginLeftVal = circle.css('marginLeft');
marginLeftVal = parseInt(marginLeftVal)*-1;
circles_container.css({
            marginLeft: marginLeftVal 
});

Upvotes: 0

Lukas
Lukas

Reputation: 7734

OK i have this and also it's work:

var margin_left = l_circle.css('margin-left').replace("px", "");
container.css('margin-left', -margin_left + 'px');

Upvotes: 0

lt.kraken
lt.kraken

Reputation: 1300

YOu could also start using the JSizes library.

Found on this page: http://www.bramstein.com/projects/jsizes/

Allows you to easily retrieve or set a property of margin, padding, or other attributes.

Upvotes: -1

A. Wolff
A. Wolff

Reputation: 74410

I would say this should be more accurate:

var margin_left = circle.css('margin-left');
circles_container.css({marginLeft: '-'+margin_left});

Upvotes: 2

Related Questions