accessing li's rel value when hovered within ul with id mainmenu3
im creating a 2 level jquery menu that when a list element is hovered upon a div is shown with a name matching the li's rel="divname" value
i have been matching it using the following code
$this.find(">li").hover().attr('rel');
but how do i only access the first level of li's that fall within using this jquery code if i have the following html?
<ul class="Menu" id="mainmenu3">
<li rel="accounts"><a href="/admin/users">ACCOUNTS</a></li>
<li rel="analytics"> <a href="/admin/analytics">ANALYTICS</开发者_如何学编程a></li>
<li rel="tags"><a href="tags">TAGS</a></li>
<li rel="settings"><a href="/admin/settings">SETTINGS</a></li>
<li rel="logout"><a href="login/logout">LOGOUT</a> </li>
</ul>
You could use the child selector to only target the first level of <li>
's when you bind your mouseover event:
$('#mainmenu3 > li').mouseover(function(){
$('div').text($(this).attr('rel'));
});
Demo of it working.
Do
$this.children('li').hover().attr('rel')
However, this will give you the 'rel' attr of the first child only.
精彩评论