user1731062
user1731062

Reputation: 35

How to make parent link active?

I'd like to use the jQuery UI menu or accordion AND have the parent node open an a href when selected in addition to perform its other function of showing its children/nested links.

I'm using the following code, but realize I probably need to configure something in the jquery-ui.js file.

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>jQuery UI Accordion - Default functionality</title>
    <link rel="stylesheet"
    href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />

    <script>
        $(function () {
            $("#accordion").accordion();
        });
    </script>
</head>

<body>
    <div id="accordion">
         <li><a href="http://www.yahoo.com" target="_blank">yahoo1</a> 
          <ul>
             <li><a href="http://www.bing.com" target="_blank">bing2</a></li>
            </ul>             
         </li>
      (...)

Example : When I click on yahoo1 I want to see the content that yahoo1 is liked to display on the page (will use ajax to call up page content) AND still display its nested bing2 child.

Essentially, I'd like to know if there's a way to make a parent li like yahoo1 an active link to open something.

Upvotes: 1

Views: 542

Answers (1)

StaticVariable
StaticVariable

Reputation: 5283

you can use ajax load() function

$("#accordian.li.a").on("click",function(){
   $("#accordian").load($(this).attr("href"));
 // you need to create a div to append the data returned by ajax call
})

Upvotes: 1

Related Questions