帮助理解JQuery Attribute Equals Selector [英] Help understanding JQuery Attribute Equals Selector

查看:119
本文介绍了帮助理解JQuery Attribute Equals Selector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在< div中找到< td role =fooclass =one two three 4> id =myid>

I want to find a <td role="foo" class="one two three four"> within a <div id="myid">

这两个选择器有效:

$('#myid td[role=foo]')

$('#myid .two')

但是这个没有,为什么?

But this one doesn't, why?

$('#myid .two td[role=foo]')


推荐答案

因为选择器字符串中的空格是后代选择器

Because a space in a selector string is a descendant-selector.

您需要这样做:

$('#myid td.two[role=foo]')

你的方式,你在寻找< td role =foo> 后代 .two 的元素。

The way you had it, you were searching for <td role="foo"> elements that are a descendant of .two.

这篇关于帮助理解JQuery Attribute Equals Selector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆