根据类获取元素的文本

时间:2015-10-06 02:09:56

标签: javascript jquery html

<ul class="vm_cat">
  <li><a class="mainlevel" href="/">MAIN LEVEL 1</a></li>
  <li><a class="sublevel" href="/">sub 1 a</a></li>
  <li><a class="sublevel" href="/">sub 1 b</a></li>
  <li><a class="sublevel" href="/">sub 1 c</a></li>
  <li><a class="sublevel" href="/">sub 1 d</a></li>
  <li><a class="mainlevel" href="" id="active">MAIN LEVEL 2</a></li>
  <li><a class="hide sublevel" href="/">sub 2 a</a></li>
  <li><a class="hide sublevel" href="/">sub 2 b</a></li>
  <li><a class="hide sublevel" href="/">sub 2 c</a></li>
  <li><a class="mainlevel" href="/" id="active1">MAIN LEVEL 3</a></li>
  <li><a class="hide sublevel" href="/">sub 3 a</a></li>
</ul>

我想知道如何从hide sublevel上点击#active上的课程hide。我不想从sublevel旁边的#active1移除<?php $sql3="SELECT album.kategori_album, album.id_album, gallery.jdl_gallery, gallery.gbr_gallery FROM gallery INNER JOIN album ON gallery.id_album = album.id_album WHERE album.kategori_album = 'architecture'"; $aksi3 = mysql_query($sql3); $num_rows3 = mysql_num_rows($aksi3); $output2 = ''; while($data3=mysql_fetch_assoc($aksi3)){ $output2 .= '<img src="' . $SERVER . '/img_galeri/' . $data3['gbr_gallery'] . '" alt="" align="center" height="350">'; } ?> <?php $sql2="SELECT album.kategori_album, album.id_album, gallery.jdl_gallery, gallery.gbr_gallery FROM gallery INNER JOIN album ON gallery.id_album = album.id_album WHERE album.kategori_album = 'architecture' GROUP BY album.id_album"; $aksi2 = mysql_query($sql2); while($data2=mysql_fetch_array($aksi2)){ echo "<div class='openproject'> <div id='divnavproject_$data2[id_album]' class='project_content'> <div class='slideprojects theme-default'> <div id='slider$data2[id_album]' class='nivoSlider'> ".$output2." </div> </div> </div> </div>"; } ?>

1 个答案:

答案 0 :(得分:0)

$('.mainlevel').click(function(e){
    e.preventDefault();
    $(this).siblings('ul').toggle();
})

DEMO

使用class使用.siblings()选择同级ul并使用.toggle()

切换点按

UPDATED DEMO

更新了演示,直到第3级列表