You're missing the list ID and you're calling the selector on the console (when you want to be selecting on the document).
<script>
function dropdown()
{
document.getElementById("Menuitems").style.display="block";
}
</script>
<div id="dropdown">
<ul>
<li onclick="dropdown()"><a>Menu</a>
<ul id="Menuitems">
<li><a target='_blank' href="">item 1</a> </li>
<li><a target='_blank' href="">item 2</a> </li>
<li><a target='_blank' href="">item 3</a> </li>
</ul>
</li>
</ul>
</div>
JSFiddle: http://jsfiddle.net/tmaB9/
Try:
<li onClick="dropDown(this);">
This is important, so your function knows which element you clicked on. Then...
function dropDown(li) {
var submenu = li.getElementsByTagName('ul')[0];
if( submenu) {
submenu.style.display = submenu.style.display == "block" ? "" : "block";
}
}
This will toggle the visibility of the submenu :)
I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...
I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...
I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...
I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...
I want to move items between two Listboxes in ASP.Net using JQuery/Javascript and below is my code which is working perfectly. function AddItems() { var totalItemsSelected = 0; var ...
I want to move items between two Listboxes in ASP.Net using JQuery/Javascript and below is my code which is working perfectly. function AddItems() { var totalItemsSelected = 0; var ...
I'm trying to do a js app that would basically move some balls on a canvas element. I set the context.fillStyle = "rgba(12, 34, 56, 0.2)"; the problem is that the balls become opaque from transparent ...
I'm trying to do a js app that would basically move some balls on a canvas element. I set the context.fillStyle = "rgba(12, 34, 56, 0.2)"; the problem is that the balls become opaque from transparent ...