Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have list corresponding sub list.is it possible to do that if i click on list should display corresponding sub list in another
.
if any one have such sample please share

How can i achieve it.please help me

What I have tried:

i am thinking that when i click on list will store corresponding sub list in an array and display in another
Posted
Updated 10-Mar-16 22:23pm
Comments
[no name] 11-Mar-16 1:15am    
Please elaborate more what is sublist and put in array - provide relevant code.
Veena Hosur 11-Mar-16 1:38am    
i have list of departments in <div> called dep. When i click on one departments i want to display coresponding sub list in in <div> called sub.how can i do it
[no name] 11-Mar-16 2:10am    
Post relevant HTML code and tell what you need exactly?
Karthik_Mahalingam 11-Mar-16 1:43am    
post some code
Veena Hosur 11-Mar-16 2:00am    
its my idea.i want to achieve it i dont know how to do it

 
Share this answer
 
v2
Try something like this
modify it as per your need

CSS
CSS
<style>
        
        .sub-menu {
            display: none;
            list-style: none;
            position: absolute;
            left: 10px;
            width: 150px;
        }
    </style>


Javascript/Jquery

<script>
        $(function () {
            $('.main-menu  li').hover(
           // when hovered
           function () {
               var $li = $(this);
               if ($li.has('ul')) {
                   $('#div1').html($('ul',$li).html());
               }


           },
           // when NOT hovered
           function () {
               $('#div1').html('');
           }
       );
        });



    </script>



HTML

HTML
<ul style="list-style:none" class="main-menu">
       <li><a href="#">Item One</a></li>
       <li><a href="#">Item Two</a></li>
       <li>
           <a href="#">Item Three</a>
           <ul class="sub-menu">
               <li><a href="#">Sub Item One</a></li>
               <li><a href="#">Sub Item Two</a></li>
               <li><a href="#">Sub Item Three</a></li>
               <li><a href="#">Sub Item Four</a></li>
               <li><a href="#">Sub Item Five</a></li>
           </ul>
       </li>
   </ul>
   <div id="div1" style="height:300px; width:300px; border:1px solid red">This is my div</div>
 
Share this answer
 
html:
$(function () {
    $('.panel-body').click(
     
    // when clicked
    function () {
     
        $('#div1').html('');
        var $li = $(this);
      
        if ($li.has('ul')) {
            $('#div1').html($('ul', $li).html());
        }

    });
});


script:
$(function () {
    $('.panel-body').click(
     
    // when clicked
    function () {
     
        $('#div1').html('');
        var $li = $(this);
      
        if ($li.has('ul')) {
            $('#div1').html($('ul', $li).html());
        }

    });
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900