javascript - jQuery slide toggle corresponding service item -


working on jquery slide toggle upon click of item in ul toggle down corresponding item in ul. i'm having trouble getting click linked id , toggling correct ul item.

jquery is:

$(document).ready(function() {  //on click of subservices list item toggle down corresponding subservices item  $(".subservices").find("li").hide().end() // hide other uls .click(function(e) {     if (this == e.target) {  // if handler element event originated         $(this).children('ul.subserviceslist.subserviceitem').slidetoggle('fast');     } }); }); 

can :)

fiddle here

first, id of element must unique can't use same id subservices , subserviceslist. in below solution uses data-target attribute subservices.

also need register handler .subserviceslist a element, not subserviceslist

$(document).ready(function() {      //on click of subservices list item toggle down corresponding subservices item      $(".subservices > li").hide().end() // hide other uls    $('.subserviceslist a').click(function(e) {      $('#' + $(this).data('target')).slidetoggle()    });  });
.subserviceslist {    display: block;    width: 55%;    text-align: center;    margin-left: auto;    margin-right: auto;  }  .subserviceslist li {    display: inline;    list-style: none;    list-style-type: none;    margin-right: 10px;    text-align: center;    line-height: 26px;    cursor: pointer;  }  .subserviceslist li a:hover {    color: #333333;  }  .subservices {    width: 75%;    margin: 0 auto;  }  .subservices li.subserviceitem {    display: block;    list-style: none;    list-style-type: none;    height: auto;    clear: both;  }  .subservices li.subserviceitem .image {    float: left;    display: block;    margin-right: 10px;    margin-bottom: 10px;  }  .subservices li.subserviceitem .image {    float: left;    display: block;  }  /*.subservices li.subserviceitem { display:none; } */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <ul class="subserviceslist">    <li><a data-target="1">name 1</a></li>    <li><a data-target="2">name 2</a></li>    <li><a data-target="3">name 3</a></li>  </ul>    <ul class="subservices">    <li class="subserviceitem" id="1">      1 hwiufhwriufhiurhfiureh    </li>    <li class="subserviceitem" id="2">      2 hwiufhwriufhiurhfiureh    </li>    <li class="subserviceitem" id="3">      3 hwiufhwriufhiurhfiureh    </li>  </ul>


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -