Home  >  Article  >  Web Front-end  >  jquery中通过父级查找进行定位示例_jquery

jquery中通过父级查找进行定位示例_jquery

WBOY
WBOYOriginal
2016-05-16 17:30:58999browse
复制代码 代码如下:

如果想要查找到有icon这个class的span(对其进行操作,将news_list_icon换为news_list_icon_hover),除了用原始的代码
复制代码 代码如下:

$("#newslist li").hover(function(){
$("#newslist li").find(".icon").addClass("news_list_icon_hover") },function(){ $("#newslist li").find(".icon").removeClass("news_list_icon_hover") } );

还可以用父级查询的方法进行定位,具体如下:
复制代码 代码如下:

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(): 指的是这个标签
$(alink).parent().parent(): 指的是
  • 这个标签$(alink).parent().parent().find(".icon"): 就可以定位到想要的元素了
  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn