Hey there Kirupans,
I was doing some searching for techniques to create split-button drop-down menus (ala digg.com and the YUI split-button widget). I came across this link:
http://woork.blogspot.com/2008/01/simple-css-vertical-menu-digg-like.html
It’s a blog by Antonio Lupetti, and Mr. Lupetti does a solid job at creating the split button effect visually. I’m a bit more concerned with functionality and validity, however.
There are a couple of things I’d like to accomplish by building on the code he’s written, but being a very beginner with JavaScript, I’ll need some help from the community (you fine people!).
I figured using jQuery would be a good choice to remove any “onclick” or “onblurs” that would dirty up the code. Now, this is my first attempt at creating such a script in jQuery, but here’s what I’ve written.
<html>
<head>
<title>Split Buttons</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/splitbuttons.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("ul.menu").click(function () {
$(this > child).toggle();
});
});
</script>
</head>
<body>
<div id="middlebar">
<ul class="menu">
<li><a href="#"> Products</a></li>
<ul class="submenu">
<li><a href="#">Widgets</a></li>
<li><a href="#">Boxes</a></li>
<li><a href="#">Containers</a></li>
</ul>
</ul>
<ul class="menu">
<li><a href="#"> Support</a></li>
<ul class="submenu">
<li><a href="#">Domestic Customers</a></li>
<li><a href="#">International Customers</a></li>
<li><a href="#">Knowledge Base</a></li>
</ul>
</ul>
</div>
</body>
</html>
What I’m trying to accomplish is getting jQuery to look for any <ul> with the class “menu”, and when one is clicked, it should .toggle() the child <ul> with the class “submenu”. I’m simply not clear on the syntax. And yeah, I know the code above is probably a ways off…
This is the first step, and I’m sure I’ll have a couple more questions, but any insight would be much appreciated!
Thanks in advance,
Chris.