Just wondered how I would search for all the ids starting with "content_" in the whole page and also a way to only find them in a named div called "extra_content". Once i have all the ids i want to hide them.

Below is an example of what i want to find.

<div id="content_1"></div> <-- Find
<div id="content_2"></div> <-- Find
<div id="contet_3"></div>

<div id="extra_content"> 
    <div id="content_extra_1"></div> <-- Find
    <div id="content_extra_2"></div> < -- Find
</div>

Examples would be helpful.

谢谢

推荐答案

使用attribute-starts-with selector:

$('[id^="content_"]').hide();

To limit the search to elements within extra_content:

$('#extra_content [id^="content_"]').hide();

Jquery相关问答推荐

在添加_renderMenu方法时,是什么原因导致jQuery UI AutoComplete抛出TypeError?

jQuery找到最近的匹配元素

使用 jQuery / javascript 测试链接是否是外部的?

jQuery 1.4.1 中缺少 JSON 字符串化?

jQuery / Ajax - $.ajax() 将参数传递给回调 - 使用好的模式?

调用 jquery ajax - .fail vs. :error

jQuery 插入 div 作为某个索引

不使用插件的 jQuery 缓动函数

使用 jQuery DataTables 时禁用最后一列的排序

jquery beforeunload 关闭(不离开)页面时?

jQuery DataTables:延迟搜索直到输入 3 个字符或单击按钮

如何检测是否安装了 Flash,如果没有,显示一个隐藏的 div 通知用户?

CORS POST 请求可以使用纯 JavaScript,但为什么不使用 jQuery?

订单对象是否由指定的 jQuery Select 器返回?

jquery分别绑定双击和单击

将多个 JavaScript 文件合并为一个 JS 文件

AngularJS:使用 jQuery 更改时,ng-model 绑定不更新

使用 jQuery Select 空文本输入

如何使用 JQuery 删除onclick?

如何使用新的 JSON 数据手动更新数据表