我試圖選擇一個已經隱藏的列表項,但可以用幻燈片切換方法顯示。從jquery中隱藏的ul中選擇li
下面是HTML
<ul>
<li>item 1</li>
<li>item 2</li>
<li id="par1">parent 1</li>
<ul id="par1list">
<li>items to select1</li>
<li>items to select2</li>
<li>items to select3</li>
</ul>
<li id="par2">parent 2</li>
<ul id="par2list">
<li>items to select1</li>
<li>items to select2</li>
<li>items to select3</li>
</ul>
</ul>
在jQuery的,我躲在子父列表(par1list和par2list),但點擊父1或2家長時,他們滑動切換。這裏是jQuery的:
$(document).ready(function(){
$("#par1list, #par2list").hide(); //hide elements
$("#par1").click(function() {
$("#par1list").slideToggle(400); //click parents to show hidden elements
});
$("#par2").click(function() {
$("#par2list").slideToggle(400); //click parents to show hidden elements
});
$("#par1list > li").click(function(){ //select list item from previous hidden ul
this.css('color', 'red');
});
});
我想選擇從UL PAR1列表項,但我無法弄清楚。謝謝!
我看到了維加的答案,所以刪除了我的評論。我試圖找出你想要達到的目標。 – raddykrish