-
Mar 10th, 2013, 05:53 PM
#1
Thread Starter
PowerPoster
Selecting a menu option using jQuery?
I have a web page that contains a menu built using <div> tags. The structure is below:
Code:
<div id="mnuStructure" style="border-top: 1px Solid Gray; border-bottom: 1px Solid Gray">
<div id="opt1" class="menuItems2"><a href="#">Option 1</a></div>
<div id="opt2" class="menuItems2"><a href="#">Option 2</a></div>
<div id="opt3" class="menuItems2"><a href="#">Option 3</a></div>
<div id="opt4" class="menuItems2"><a href="#">Option 4</a></div>
<div id="opt5" class="menuItems2"><a href="#">Option 5</a></div>
</div>
What I'm trying to do, is load the menu option selected into a variable using jQuery. I'm not real good with jQuery yet some I'm kinda stuck. What is the best way to do this?
Thanks,
-
Mar 12th, 2013, 06:11 PM
#2
Re: Selecting a menu option using jQuery?
I would normally do a menu with <ul> as it is more sematically valid to have a list of items styled as a menu ("list-style-type:none", etc.).
Having said that, do you want to have a click handler for each <a> in the menu, without it actually navigating to a separate url?
-
Mar 12th, 2013, 11:22 PM
#3
Thread Starter
PowerPoster
Re: Selecting a menu option using jQuery?
Yes, that is what I am looking for. As far as the navigation goes, depending on the menu option selected, it will only display a <div> and not redirect to another page.
-
Mar 13th, 2013, 07:02 PM
#4
Re: Selecting a menu option using jQuery?
http://jsfiddle.net/HRTr8/
http://css-tricks.com/return-false-and-prevent-default/
Keep in mind that jQuery UI has a Menu widget, which may or may not do what you want. Why re-invent the wheel every time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|