Function doesn't work with conditions

Hi,
Function doesn’t work with conditions , but works without them ,
I need a condition in the function so i can pause, start a slideShow.
Please how do i do this.


<div class="pause"><a href="javascript:pause();" style="z-index:15" >Pause</a></div>
<script type="text/javascript" >
var paused=0;
function pause(){
		var pauseNode=document.getElementsByClassName("pause")[0];
	if(pauseNode.firstChild.nodeValue=="Pause"){
		pauseNode.firstChild.nodeValue="Start";
		that.paused=1;
		clearInterval(that.loop);
	}else if(pauseNode.firstChild.nodeValue=="Start"){
		pauseNode.firstChild.nodeValue="Pause";
		that.paused=0;
		that.loop=setInterval(next,1000);
		}
        alert(that.paused); //outputs 0
/*Works 
pauseNode.firstChild.nodeValue=="Pause";
		pauseNode.firstChild.nodeValue="Start";
		that.paused=1;
		clearInterval(that.loop);
	alert(that.paused); //outputs 1
*/
}
</script>

Give the link a unique id, and get that style attribute the mother-loving hell outta there, and into a CSS declaration instead.


#pause {
    z-index:15
}


<a id="pause">Pause</a>

Then, once the body has loaded, attach an onclick event on to the pause link. That’s most easily done by placing the script at the end of the body, just before the </body> tag.


function pause() {
    ...
}
document.getElementById('pause').onclick = pause;

If the issue you’re facing is more complex than that, then I’m sorry. I’m still distracted by being in a earthquake zone where my home has no power, no water, and no sewage.

For further assistance, please link to a test page on the web that demonstrates the problem you’re facing, so that more effective assistance can be granted.

i’ve posted different html in my first post. :blush:
the html i was trying is this./with js function for better reading :stuck_out_tongue:


<a class="pause" href="javascript:pause();" >Pause</a>
<script type="text/javascript" >
var paused=0;
function pause(){
		var pauseNode=document.getElementsByClassName("pause")[0];
	if(pauseNode.firstChild.nodeValue=="Pause"){
		pauseNode.firstChild.nodeValue="Start";
		that.paused=1;
		clearInterval(that.loop);
	}else if(pauseNode.firstChild.nodeValue=="Start"){
		pauseNode.firstChild.nodeValue="Pause";
		that.paused=0;
		that.loop=setInterval(next,1000);
		}
        alert(that.paused); //outputs 0
/*Works 
pauseNode.firstChild.nodeValue=="Pause";
		pauseNode.firstChild.nodeValue="Start";
		that.paused=1;
		clearInterval(that.loop);
	alert(that.paused); //outputs 1
*/
}
</script>

That html does not work with the first pause() function.
but placed inside a div element like this.


<div class="pause"><a href="javascript:pause();" >Pause</a></div>

can be reached in javascript like this.


function pause(){
	var pauseNode=document.getElementsByClassName("pause")[0];
	var a=document.getElementsByTagName("a")[1]; // second anchor element
	if(a.firstChild.nodeValue=="Pause"){
		a.firstChild.nodeValue="Start";
		that.paused=1;
		clearInterval(that.loop);
	}else if(a.firstChild.nodeValue=="Start"){
		a.firstChild.nodeValue="Pause";
		that.paused=0;
		that.loop=setInterval(next,1000);
		}
	}

and it works.
Thanks for you help.
Hope you have power,watter, and sewage soon. (our power supplier stops our power for 3 times in the last 3 days, probably not relatated but it sux.)
Bye.