Solved

Jquery - Change <ul> content on specific <li> click

Posted on 2014-09-16
2
1,010 Views
Last Modified: 2014-09-16
Hi,

See attached HTML. I want to change the content (<li> list) of a <ul> when specific list items are clicked.

I found the attached Jquery on the web; it doesn't work, you can try it at http://rkassoc.org/Davis/menu/menu_test.htm. Click the top list item (Irrigation).

How can I make this work, Obviously, the replacement list is just a test, real content is more elaborate.

Thanks,

Rkorts
menu-test.htm
0
Comment
Question by:Richard Korts
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40326590
As you have the function before the code actually exists it won't work as it doesn't exist in the DOM yet, you need to either move the jquery to the end of the page or wrap it in a doc ready function e.g.
$(function () {
    $('#irr').click(function () {
        $('#menu').html('<li>Context x</li><li>Context y</li><li>Context z</li>');
    });
})

Open in new window

0
 

Author Closing Comment

by:Richard Korts
ID: 40326722
Perfect!

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
2 separate CSS animations 2 29
selected value 16 24
Flex container in CSS 8 22
bootstrap css color change 10 16
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question