skaterdav85 Posted February 24, 2009 Share Posted February 24, 2009 So here is my routine. I want to abort the script inside the first if statement, so that when you click once, the div is displayed, and when you click a 2nd time, it hides. But this doesnt work if you reset x equal to 0, because it just keeps the div displayed. And if you dont reset x to 0, the 3rd click (if you wanted to show the div again), wont do anything. Any ideas?<script language="javascript">var x = 0;function showBody() {if(x == 1) { document.getElementById('body').style.display='none'; x=0;//NEED EXIT OR ABORT FUNCTION HERE............................................... }if(x == 0) { document.getElementById('body').style.display='block'; x = 1;}}</script><div onclick="showBody();">click here</div><div id="body" style="display:none;">this is the hidden body</div> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 24, 2009 Share Posted February 24, 2009 Just use return.function showBody() {if(x == 1) {document.getElementById('body').style.display='none';x=0;return;}... Link to comment Share on other sites More sharing options...
skaterdav85 Posted February 24, 2009 Author Share Posted February 24, 2009 Just use return.function showBody() {if(x == 1) {document.getElementById('body').style.display='none';x=0;return;}...what does return do? Ive never really been familiar with this, except the fact it can return a value. what does return alone do? Link to comment Share on other sites More sharing options...
jeffman Posted February 24, 2009 Share Posted February 24, 2009 It exits the function immediately. Doesn't matter if you're in a loop or whatever. Just BANG and you're out. Control passes to the statement that follows the statement that called the function in the first place. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.