Hi I'm trying position new dom element same as old one, and then hide old one so new would replace it: http://jsfiddle.net/jC33F/5/
Though if original element has margin:auto jQuery can't retrieve it. Is there a way to be able to determine if element has margin:auto; ?
Edit: Thanks to @Vibhu I came up with this http://jsfiddle.net/jC33F/43/ looks horrible :D And I'm not sure it will always work.
Feel free to suggest something better.
This might be crazy, but what about something like this for checking it an element has margin: 0 auto
(cannot seem to find any other way):
var margin = $("#parent").css("margin");
if($('#parent').position().left*2 == ($('#parent').parent().innerWidth() - $('#parent').outerWidth())) {
margin = "0px auto";
}
$("#positionable").css({
position: $("#parent").css("position"),
top: $("#parent").css("top"),
left: $("#parent").css("left"),
margin: margin
});
$("#parent").hide();
This code basically checks if the left value of #parent is equal to half the space between the 2 edges of its container. Worked for me in this case, might fail in other cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With