CSS/JQuery Hover Affect Only Hovered Element and Not Parent -
i have list of nested items, each has it's own edit link.
<ul> <li>coffee</li> <li> fruits <a href="#" class="editlink">edit</a> <ul> <li>banana <a href="#" class="editlink">edit</a></li> <li>orange <a href="#" class="editlink">edit</a></li> <li> apple <a href="#" class="editlink">edit</a> <ul> <li>fuji <a href="#" class="editlink">edit</a></li> <li>red delicious <a href="#" class="editlink">edit</a></li> <li>golden <a href="#" class="editlink">edit</a></li> </ul> </li> </ul> </li> <li> drinks <a href="#" class="editlink">edit</a> <ul> <li>coke <a href="#" class="editlink">edit</a></li> <li>pepsi <a href="#" class="editlink">edit</a></li> </ul> </li> <li>something <a href="#" class="editlink">edit</a></li> </ul>
i want edit link display when 1 hovers on list element. when hover on child element, parent affected well.
$('li').hover( function(){ $(this).find('.editlink').show(); }, function(){ $(this).find('.editlink').hide(); } );
i have following css make edit link hidden initially
.editlink{ display:none; }
how make hovered element has edit link show , not others? seems hide part fine show part affects nested parents. here sample in action: http://jsfiddle.net/d7ywm/
give try. uses direct child selector (http://jsfiddle.net/d7ywm/4/):
$(document).ready(function(){ $('li').hover( function(ev){ var li = $(this); li.parents('li').find('>.editlink').hide(); if ( ! li.find('li > .editlink:visible').length ) { li.find('>.editlink').show(); } }, function(){ var li = $(this); li.find('>.editlink').hide(); li.parents('li:first').find('>.editlink').show(); } ); });
if want localized text, you're going have wrap text in <span>
or , use instead.
ul { list-style-position: inside; }
and if doesn't work you, may have @ different way of adding bullets. or use starting point figuring rest out...
Comments
Post a Comment