1

HTML:

<script>function dropdown()
{        console.getElementById("").style.display="block";
}</script>
<div id="dropdown">
    <ul>
        <li onclick="dropdown()"><a>Menu</a>
             <ul id="Menuitems">
                 <li><a href="">item 1</a> </li>
                 <li><a href="">item 2</a> </li>
                 <li><a href="">item 3</a> </li>
            </ul>
        </li>
    </ul>
</div>    

Css:

#dropdown ul{
 display: block; 
}
#dropdown ul li {
     display: block;
     background-color: #558c89;
     color: #ffffff; 
}
#dropdown ul li ul {
     display: none; 
}
#dropdown ul li:hover > ul { /*this is what the onclick event should do*/
     display: block; 
}

The onclick should start the function "dropdown()" which needs to: "display: block;" on #dropdown ul li

9
  • 1
    This makes no sense at all. Commented May 20, 2014 at 13:42
  • @techouse meta.stackoverflow.com/questions/253086/code-block-adjustment Commented May 20, 2014 at 13:42
  • where is your html? create a jsfiddle and what is your question? Commented May 20, 2014 at 13:42
  • What's console.getElementById("")? Commented May 20, 2014 at 13:44
  • do you have a restriction on using JQuery ? Commented May 20, 2014 at 13:44

3 Answers 3

3

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 href="">item 1</a> </li>
                 <li><a href="">item 2</a> </li>
                 <li><a href="">item 3</a> </li>
            </ul>
        </li>
    </ul>
</div>  

JSFiddle: http://jsfiddle.net/tmaB9/

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

here is a quick example of what i think you want (provided you can use JQuery):

    $(document).ready(function () {
        $('#dropdown ul li').on('click', function dropdown() {
            //console.getElementById("").style.display = "block";
        });
    });

<div id="dropdown" class="dropdown">
    <ul>
        <li>menu 1</li>
        <li>menu 2</li>
        <li>menu 3</li>
        <li>menu 4</li>
    </ul>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.