Im trying to do the following:
Have 3 divs which are placed side by side. each has a two links 'left' and 'right'. Say on click of the 'left' hyperlink of the 2nd div(middle), the 1st div should take the place of the middle div, while the middle one should take the place of the 1st place.
I'm using the prop offsetLeft, however have run into some issues. My code is shown below:
Expand|Select|Wrap|Line Numbers
- <HTML>
- <HEAD>
- <TITLE>Document Title</TITLE>
- </HEAD>
- <BODY>
- <SCRIPT language="JavaScript">
- function moveDivs(){
- var movDiv_1 = document.getElementById('ContentMain_1');
- var movDiv_2 = document.getElementById('ContentMain');
- movDiv_1.style.position = 'relative';
- movDiv_1.style.left = parseInt(movDiv_2.offsetLeft) + 'px';
- movDiv_2.style.position = 'relative';
- movDiv_2.style.left = parseInt(movDiv_1.offsetLeft) + 'px';
- //alert("ContentMain_1 top position" + movDiv_1.offsetTop);
- //alert("ContentMain_1 left position" + movDiv_1.offsetLeft);
- //alert("ContentMain top position" + movDiv_2.offsetTop);
- //alert("ContentMain left position" + movDiv_2.offsetLeft);
- }
- </SCRIPT>
- <Body>
- <div id="ContentMain" style="float:left;width: 200px; height: 24px; overflow: visible;background-color:#cecece">
- <div style="float:left">Content 1</div>
- <div><a href="#" style="float:right;text-decoration:none">Right</a><a href="#" style="float:right;padding-right:3px;text-decoration:none">Left</a></div>
- </div>
- <div id="ContentMain_1" style="float:left;padding-left:20px;">
- <div style=" width: 200px; height: 24px; overflow: visible;background-color:#cecece">
- <div style="float:left">Content 2</div>
- <div><a href="#" style="float:right;text-decoration:none">Right</a><a href="#" onclick="moveDivs();" style="float:right;padding-right:3px;text-decoration:none">Left</a></div>
- </div>
- </div>
- <div id="ContentMain_2" style="float:left;padding-left:20px;">
- <div style="width: 200px; height: 24px; overflow: visible;background-color:#cecece">
- <div style="float:left">Content 3</div>
- <div><a href="#" style="float:right;text-decoration:none">Right</a><a href="#" style="float:right;padding-right:3px;text-decoration:none">Left</a></div>
- </div>
- </div>
- </BODY>
- </HTML>
Thanks in advance.