dimanche 29 mars 2015

JavaScript reference html5 semantic tag

I'm new to JavaScript and this site. I need help with trying to toggle a div's visibility, the div is a html semantic tag ('nav') and I can't find a way to reference it.


I have searched for a good hour and have tried 'document.getElementById()' but that doesn't work unless I change the tag to ''.


My JavaScript code is as follows:



function toggle_visibility(id) {
"use strict";

var e = document.getElementById(id);

if (e.style.display === 'block') {

e.style.display = 'none';
} else {

e.style.display = 'block';
}}


And I'm calling it from another div in my html like this



<a href="#" onclick="toggle_visibility('nav');"><div id="mNav"></div></a>

<nav>
<ul>
<a href=""><li>
Link 1
</li></a>
<a href=""><li>
Link 2
</li></a>
<a href=""><li>
Link 3
</li></a>
</ul>
</nav>

Aucun commentaire:

Enregistrer un commentaire