单击p元素显示/隐藏li

时间:2017-05-24 09:12:33

标签: javascript jquery html show-hide

我希望有可能通过点击p来显示/隐藏ul。我的HTML看起来像这样: -

<li class="type_unknown depth_2">
   <p class="tree_item branch">
        <a href="http://moodlelive.dev/mod/wiki/view.php?pageid=1123">
            <span class="glyphicon glyphicon-spacer"></span> &nbsp;Daoust University Refreshs
        </a>
    </p>
   <ul id="yui_3_15_0_4_1495615549528_188">
      <li class="type_unknown depth_3">
         <p class="tree_item leaf">
            <a href="http://moodlelive.dev/mod/wiki/view.php?pageid=1257"><span class="glyphicon glyphicon-spacer"></span> &nbsp;REFRESH DIVERSITEIT</a>
        </p>
      </li>
      <li class="type_unknown depth_3">
         <p class="tree_item leaf">
            <a href="http://moodlelive.dev/mod/wiki/view.php?pageid=1230"><span class="glyphicon glyphicon-spacer"></span> &nbsp;REFRESH DOELGROEPENVERMINDERINGEN</a>
        </p>
      </li>
      <li class="type_unknown depth_3" id="yui_3_15_0_4_1495615549528_187">
         <p class="tree_item leaf wiki_newentry" id="yui_3_15_0_4_1495615549528_186">
            <a href="http://moodlelive.dev/mod/wiki/view.php?pageid=1167"><span class="glyphicon glyphicon-spacer"></span> &nbsp;REFRESH FEESTDAGEN</a>
        </p>
      </li>
      <li class="type_unknown depth_3">
         <p class="tree_item leaf">
            <a href="http://moodlelive.dev/mod/wiki/view.php?pageid=1270"><span class="glyphicon glyphicon-spacer"></span> &nbsp;REFRESH VREEMDELINGEN</a>
        </p>
      </li>
   </ul>
</li>

您可以在我的 li 中看到 p标记,还有 ul标记。布局如下所示:

enter image description here

但我希望有可能让它打开或关闭。

打开

enter image description here

闭: enter image description here

因此,当您点击它时,内容会打开或关闭。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

你可以这样做: -

application/json

例如: -

$('.tree_item').click(function(e){
  e.stopPropagation();
  $(this).next('ul').toggle();
});
$('.tree_item').click(function(e){
  e.stopPropagation();
  $(this).next('ul').toggle();
});
ul,li{
list-style:none;
}