I'm trying to add a inline-style using JavaScript as soon as the site is loaded (can't use CSS directly due to reasons). I want all text within a table to be horizontally centered,
This is my JavaScript code so far:
window.onload = center_content();
function center_content (){
var all_td = document.getElementsByTagName('table');
all_td[0].style.textAlign = "center !important";
}
Edit: Code corrected so far
jsfiddle: http://jsfiddle.net/GinSan/h46mz6na/4/ (remember that I can't directly use CSS in this case)
Any help is much appreciated. No jQuery solutions please.
all_td[0].style.text-align = "center !important";is interpreted asall_td[0].style.text - align = "center !important";, i.e. it tries to subtractalignfromall_td[0].style.text. Then you are trying to assign a value to that value, which doesn't make sense to the engine.