drop down menu

how to make the dropdown menu appear on focus of the link menu.
on tabbing it should navigate to the items and on after last item it should close the dropdown menu.
please help.

<!DOCTYPE html>
<head>
<style>
.hide {
	display:none;	
}
</style>
</head>
<body>
<a href="#">Menu</a>
<ul class="hide">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
<li><a href="#">item 4</a></li>
<li><a href="#">item 4</a></li>
</ul>
</body>
</html>

Open in new window

codelevelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Habib PourfardSoftware DeveloperCommented:
You can do it by use of jQuery:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        .hide {
            display: none;
        }
    </style>
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    <script>
        $(function () {
            $("#menu-container").focusin(function () {
                $(this).find(".dropdown").show();
            });
            $("#menu-container").focusout(function () {
                $(this).find(".dropdown").hide();
            });
        });
    </script>

</head>
<body>
    <div id="menu-container">
        <a href="#">Menu</a>
        <ul class="dropdown hide">
            <li><a href="#">item 1</a></li>
            <li><a href="#">item 2</a></li>
            <li><a href="#">item 3</a></li>
            <li><a href="#">item 4</a></li>
            <li><a href="#">item 4</a></li>
        </ul>
    </div>
</body>
</html>

Open in new window

0
codelevelAuthor Commented:
once i tab from the menu link the sub menus dissappear rather than going to the first submenu link.
0
Habib PourfardSoftware DeveloperCommented:
sorry it took a while to get back to you. I was testing it on chrome and it was working. but after I tested that in Firefox I found that the solution is not working so I spent more time to figure out what's wrong. here is the solution:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        .hide {
            display: none;
        }
    </style>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script>
        $(function () {
            $(".menu-container").focusout(function () {
                var $container = $(this);
                setTimeout(function () {
                    var $newFocus = $(':focus');
                    if (!$container.find($newFocus).length)
                        $container.find(".dropdown").hide();
                }, 10);
            });
            $(".menu-container").focusin(function () {
                $(this).find(".dropdown").show();
            });

        });
    </script>

</head>
<body>
    <div class="menu-container">
        <a href="#">Menu</a>
        <ul class="dropdown hide">
            <li><a href="#">item 1</a></li>
            <li><a href="#">item 2</a></li>
            <li><a href="#">item 3</a></li>
            <li><a href="#">item 4</a></li>
            <li><a href="#">item 5</a></li>
        </ul>
    </div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codelevelAuthor Commented:
works. thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.