Below, how should I select the elements that contain the class my_class within the element with id = "my_id"?

Note that the element may also have another class, which I am not selecting for.

<div id = "my_id">
    <span class = "my_class hidden">hi</span>
    <span class = "my_class">hello</span>
</div>

was trying

$("#my_id [class*=my_class ]")

推荐答案

You can use the class selector along with descendant selector

$("#my_id .my_class")

Jquery相关问答推荐

缺少 .map 资源?

jQuery 的元素或类 LIKE Select 器?

Jquery Ajax,从 mvc.net 控制器返回成功/错误

在jQuery中获取所有选定复选框值的最佳方法

如何判断是否有任何 JavaScript 事件侦听器/处理程序附加到元素/文档?

为特定请求禁用 ajaxStart() 和 ajaxStop()

即使通过Javascript代码判断,如何触发复选框单击事件?

如何在实际图像下载时显示加载图像

使用 jQuery Select 最后 5 个元素

jQuery:value.attr 不是函数

隐藏 div 但保留空白

为 jQuery AJAX 调用实现加载指示器

虽然未定义变量 - 等待

在jquery中查找具有某个属性值的所有元素

jQuery 日期 Select 器 - 禁用过go 的日期

Url.Action 在我的 url 中放了一个 &,我该如何解决这个问题?

设置 JQuery event.preventDefault() 时绕过 window.open 上的弹出窗口阻止程序

使用 jQuery 将事件侦听器添加到动态添加的元素

detach()、hide() 和 remove() 之间的区别 - jQuery

JavaScript 在 DOM 中移动元素