无法访问子元素 - jquery
我有一个类似 HTML
<div class="a">
<div class="b">
something
</div>
<div class="c">
<div class="subC">
i want to access
</div>
</div>
</div>
和 jquery 的东西,
$('.a').hover(function(){
$(this).children('.subC').fadeOut();
})
我想访问“subC”类,但上面不起作用。
我也尝试过
$('.a').hover(function(){
$(this).children('.c .subC').fadeOut();
})
,但这也不起作用!
这个问题有什么办法解决啊!我做错了什么吗?请帮忙
I have a HTML like
<div class="a">
<div class="b">
something
</div>
<div class="c">
<div class="subC">
i want to access
</div>
</div>
</div>
and jquery like
$('.a').hover(function(){
$(this).children('.subC').fadeOut();
})
I Want to access the class "subC" but above is not working.
i also tried
$('.a').hover(function(){
$(this).children('.c .subC').fadeOut();
})
but this too is not working !
Whats the solution to this problem ! am i doing anything wrong ? please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
children
只深入一层。请尝试使用find()
来代替。http://api.jquery.com/children/
children
only goes one level deep. Tryfind()
instead.http://api.jquery.com/children/
当在 jQuery 闭包内时,
this
引用上一个 jQuery 操作返回的 jQuery 对象:在闭包内使用
this
设置当前 jQuery 对象内查询的范围:When inside a jQuery closure,
this
refers to the jQuery object returned by the previous jQuery operation:Use
this
within the closure to set the scope for querying inside the current jQuery object:使用
.find('selector')
查找深度子节点Use
.find('selector')
to find deep children正如 Rob 所说,使用
.find
来查找深层元素。如果你想使用
.children
,请写As Rob says, use
.find
to find deep elements.if you want to use
.children
, write