
September 25th, 2012, 05:05 PM
|
|
|
|
Using setInterval to rotate div content
I love me some PHP, CSS, HTML, and even a little jQuery. But I use Javascript so infrequently, that I easily stumble on things like this.
I'm trying to write a simple script that will rotate through 3 divs of content. For whatever reason, my code hates me and won't advance past 'div2'. I'd love to use jQuery, but it gets stripped out of the module I'm using. Only pure javascript sneaks through.
Code:
<script type="text/javascript">
function rotateDivs(){
if (rotateDiv = 2){
document.getElementById('div1').style.display = 'none';
document.getElementById('div2').style.display = '';
rotateDiv=3;
}
else if (rotateDiv = 3){
document.getElementById('div2').style.display = 'none';
document.getElementById('div3').style.display = '';
rotateDiv=1;
}
else {
document.getElementById('div1').style.display = '';
document.getElementById('div3').style.display = 'none';
rotateDiv=2;
}
}
onload = function(){
setInterval(rotateDivs, 3000);
};
</script>
Code:
<div id="div1">
<p>This is Div 1</p>
</div>
<div id="div2" style="display: none;">
<p>This is Div 2</p>
</div>
<div id="div3" style="display: none;">
<p>This is Div 3</p>
</div>
Help?
|