JavaScript JS using onclick event on li to display block using onclick event in javascript,onclick with event,using jquery

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/

Answer:1

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 :)

Answer:2

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 ...

  1. javascript empty string falsey
  2. javascript empty string truthy
  3. javascript empty string check
  4. javascript empty string vs null
  5. javascript empty string if null
  6. javascript empty string constant
  7. javascript empty string array
  8. javascript empty string is false
  9. javascript empty string to 0
  10. javascript empty string equals null
  11. javascript empty string regex
  12. javascript empty string to null
  13. javascript empty string is undefined
  14. javascript empty string boolean value
  15. javascript empty string to number
  16. javascript empty string vs undefined
  17. javascript empty string instead of undefined
  18. javascript empty string object key
  19. javascript empty string object
  20. javascript empty string validation

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 ...

  1. getelementbyid not returning value

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 ...

  1. move items between sharepoint lists
  2. move items between vaults 1password
  3. move items between characters destiny 2
  4. move items between two select lists
  5. move items between calendars in outlook
  6. move items between layers indesign
  7. move items between two listbox c#
  8. move items between settlements fallout 4
  9. move items between listboxes c#
  10. move items between listboxes vba
  11. move items between listboxes
  12. move items between two listboxes javascript
  13. move items between folders in sharepoint
  14. move items between keychains
  15. move items between two select lists bootstrap
  16. move items between lists angular
  17. move items between list view javafx
  18. zotero move items between collections
  19. rimworld move items between stockpiles
  20. bdo move items between characters

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 ...