Tuesday, September 29, 2009

[jQuery] simple click drop down menu

Hi,

I need help to close the ul back up when i click on the white space or
on the options link.

This is what i've got so far

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.2/jquery.min.js
"></script>
<script type="text/javascript">
$(function(){
$('.menu').click(function(){
$(this).next('ul').css({'visibility':'visible'});
});
});
</script>
<style type="text/css">
* {margin:0; padding:0;}
.menu { position:relative;}
ul { position:absolute; visibility:hidden; border:solid 1px blue }
ul a {display:block;}
</style>
</head>

<body>
<a href="#" class="menu">options</a>
<ul>
<li><a href="#">game</a></li>
<li><a href="#">music</a></li>
<li><a href="#">movie</a></li>
</ul>

</body>
</html>

No comments: