I want a dynamical margin-left on a given div.
I tried this code :
window.onload = function()
{
var pageWidth = window.innerWidth;
var size = (pageWidth - 200 ) / 2;
$('#search').css('margin-Left', size));
alert(size);
};
which doesn't work (the alert is here just for test purpose), the problem is coming from the ligne $('#search').css('margin-Left', size));
but I can't find out where...
I've tried with a lowercase l
on margin-left and didn't work.
Would the following work for you?
document.getElementById("search").style.marginLeft = size + "px";
You need to specify the type of unit you want to use.
$('#search').css('margin-left', size + 'px');
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