如何选择子元素具有特定属性值的元素父元素 [英] how to select an element's father that the child has specific attribute value
本文介绍了如何选择子元素具有特定属性值的元素父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
$( < span class =code-string>#Panel ul li a)。find( [value ='art6'])。parent()。css( 这里的样式 );
i想要访问A的父亲李,并操纵它!
但它确实不工作怎么办?
plz help!
解决方案
( #Panel ul li a)。find( < span class =code-string> [value ='art6'])。parent()。css( 这里的样式);
i想要访问A的父亲Li,并操纵它!
但它不起作用我怎么能这样做?
plz help!
在jQuery中,find()
方法是
获取当前每个元素的后代一组匹配的元素,由选择器,jQuery对象或元素过滤。
所以问题是你的第一个选择器一直到锚点本身,然后你的find()正在寻找一个锚的后代。
改为这个它会起作用:
(#Panel ul li)。find(a [value ='art6'])。parent()。css(styles here);
i have this code:
$("#Panel ul li a").find("[value='art6']").parent().css("styles here");
i want to access the Li , father of A , and manipulate it!
but it does not work how can i do that?
plz help!解决方案("#Panel ul li a").find("[value='art6']").parent().css("styles here");
i want to access the Li , father of A , and manipulate it!
but it does not work how can i do that?
plz help!
In jQuery, thefind()
method is to
"Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element."
So the problem is that your first selector goes all the way down to the anchors themselves, then your find() is looking for a descendant of an anchor.
Change to this and it will work:
("#Panel ul li").find("a[value='art6']").parent().css("styles here");
这篇关于如何选择子元素具有特定属性值的元素父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文