In js the parent level is used to locate the element

  • 2020-03-30 03:20:53
  • OfStack

 
<ul id= " newslist " > 
<li> <span class="fr w160 tl">2013-06-24</span> 
<span class="news_list_icon fl mr8 icon" ></span> 
<span class="fl"><a href="{href}" onmouseover="javascript:changeReadIconOver(this);" onmouseout="javascript:changeReadIconOut(this);"> Good health leads to good luck </a></span>' 
</li> 
</ul> 

If you want to find a span with the icon class (to do that, replace news_list_icon with news_list_icon_hover), except with the original code
 
$("#newslist li").hover(function(){ 
$("#newslist li").find(".icon").addClass("news_list_icon_hover") },function (a) { $("#newslist li").find(".icon").removeClass("news_list_icon_hover") } ); 

You can also use the method of parent query to locate, as follows:
 
function changeReadIconOver(alink) { 
$(alink).parent().parent().find(".icon").addClass("news_list_icon_hover"); 
} 
function changeReadIconOut(alink) { 
$(alink).parent().parent().find(".icon").removeClass("news_list_icon_hover"); 
} 

$(alink). Parent (): refers to < Span class = "fl" > This tag
$(alink).parent().parent(): refers to < Li> This tag $(alink).parent().parent().find(".icon"): locates the desired element

Related articles: