Skip to content Skip to sidebar Skip to footer

Javascript Onclick Link Text Change

I'm working on a new page and for the mobile version I'm going to make a navigation toggle in order to hide and to show the navigation. HTML code :

Solution 1:

Moved the id from div to the a.

See it working in jsbin http://jsbin.com/eqeheb/5/watch

<div> <a id="toogleNavigation" onclick="toggle_visibility('nav_header','nav_header_level2');">Navigation Einblenden</a> </div>

Solution 2:

Make change like this.... HTML code

<div id="toogleNavigation">
    <a id="divInner" onclick="toggle_visibility('nav_header','nav_header_level2');">
        Navigation Einblenden
    </a>
</div>

And JavaScript Code

functiontoggle_visibility(id, id2) {
   var e = document.getElementById(id);
   var f = document.getElementById(id2);
   if(e.style.display == 'block' ||
      ( e.style.display == 'block' &&            
      f.style.display == 'block' ) ) {
        e.style.display = 'none';
        f.style.display = 'none';
        document.getElementById('divInner').innerHTML = "Navigation  1einblenden";
      } 
      else {
        e.style.display = 'block';
        f.style.display = 'block';
        document.getElementById('divInner').innerHTML = "Navigation 2ausblenden";
      }
}

This will work for you as its working fo

Post a Comment for "Javascript Onclick Link Text Change"