html - javascript toggle needs to stay -


hi guys need javascript, have toggle function text, waht can see on www.jasperscheper.nl want make text stay when double click on over mij , home.

this code:

var bannertext1 = document.getelementbyid('bannertext1');  var bannertext2 = document.getelementbyid('bannertext2');  var displayedbannertext = 1;    function togglebannertext() {    if(displayedbannertext == 1) {      // switch bannertext 2      bannertext1.classname += ' hidebannertext';      displayedbannertext = 2;      bannertext2.classname = 'welkom';    } else {      bannertext2.classname += ' hidebannertext';      displayedbannertext = 1;      bannertext1.classname = 'welkom';    }   }
<li class="knop" >        <button class="button" href="#"onclick="togglebannertext()"> <h3>home</h3></button>   </li>  <li class="knop">     <button class="button" onclick="togglebannertext()" href="#"><h3>over mij</h3></button>  </li>

thanks in advance,

jasper scheper.

problem: calling function togglebannertext() every time there click on of buttons, there no button's click events distinguished, every click assumes need show other text 1 shown.

solution: change html pass parameter function saying section wants show. eg: togglebannertext('home')

<li class="knop" >     <button class="button" href="#"onclick="togglebannertext('home')"> <h3>home</h3></button>  </li>  <li class="knop">  <button class="button" onclick="togglebannertext('over')" href="#"><h3>over mij</h3> </button>  <!-- there typo had </a> here changed --> </li> 

now change function accept parameter , show particular text .

function togglebannertext(section) {   if(section === "over") {     // switch bannertext 2     bannertext1.classname = 'hidebannertext';      // have removed +       bannertext2.classname = 'welkom';   }    else if (section === "home"){     bannertext2.classname = 'hidebannertext';      // + has been removed      bannertext1.classname = 'welkom';    }   else{     // none of 2 buttons clicked.   } } 

i have tested code against site , working fine


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -