Reposition <div> with Javascript
html, javascript
Solution
Using setAttribute is unreliable if you want the change to be reflected in the document. Use Element.style instead:
var el = document.getElementById('Div1');
el.style.position = 'absolute';
el.style.left = '397px';
el.style.top = '882px';
el.style.height = '30px';
el.style.width = '181px';
el.style.marginTop = '0px';
Problem
I am trying to reposition a div on the page depending on a certain condition. ``` if (somecondition) document.getElementById("Div1").setAttribute("style", "position: absolute; left:297px; top:882px; height: 30px; width: 181px; margin-top: 0px;"); ``` It is not repositioning the div in the html below: ``` <div id="Div1" style="top:366px; left:134px; position:absolute; height: 30px; width: 175px;"> ``` Other code in the if fires. Can anyone help? Browser: IE8