我正在尝试获取列表子元素的文本。但是我只能访问我不知道如何访问子元素的父元素。
HTML
<ul class="nav nav-list">
<li class="active">
<a href="javascript:void(0);">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>
</li>
<li>
<a class="dropdown-toggle" href="javascript:void(0);">
<i class="icon-text-width"></i>
<span class="menu-text"> posts </span>
<b class="arrow icon-angle-down"></b>
</a>
<ul class="submenu">
<li>
<a href="javascript:void(0);">
<i class="icon-text-width"></i>
Add New Post
</a>
</li>
<li>
<a href="javascript:void(0);">
<i class="icon-text-width"></i>
Blog
</a>
</li>
<li>
<a href="javascript:void(0);">
<i class="icon-desktop"></i>
News Letter
</a>
</li>
</ul>
</li>
</ul>
和 jQuery
$(document).on('click', '.nav-list > li', function(){
$('.nav-list > li').removeClass('active');
$(this).addClass('active');
var text=$('.active >a >span').text();
alert(text);
});
任何帮助,将不胜感激。