I have a page that is receiving a big left margin from a global style sheet that I’m not allowed to change. The margin is actually written inline by the script/stylesheet so I can’t change it in my print style.
I was able to find a jQuery solution that seems to work in FF and IE, but unfortunately not in Chrome.
jquery function:
$('#page').each(function(idx,el){
el.style.margin='';
});
I’ve tried everything from the jquery css.(‘margin-left’,’0′) to using the DOM attributes and nothing works! Any help is much appreciated.
document.getElementById("page").style.margin="0";
document.getElementById("page").setAttribute("margin","0");
document.getElementById("page").setAttribute("margin-left","0");
Description
If you are using jQuery, you should use the jQuery functions because there are made for cross browser compatibility.
The Problem is that you are using an
id. Aidshould be unique in your document. jQuery knows that you are using theid selectorand changes only the first element.Use a class instead. Check out the jsFiddle demonstration i have created.
Sample
Css
jQuery
More Information
Update
But ok, you said that the page is an existing one and you want not change from
idto `class. That is not standard and not good for search engine optimization.You can do this to get it work with
id.Sample
Html
jQuery