jQuery查找以字符串开头的所有ID? [英] Jquery find all ids starting with a string?

查看:706
本文介绍了jQuery查找以字符串开头的所有ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道我将如何在整个页面中搜索所有以"content_"开头的id,以及一种仅在名为"extra_content"的命名div中查找它们的方法.一旦获得所有ID,我就想将其隐藏.

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>

示例会有所帮助.

谢谢

推荐答案

使用属性-使用选择器启动:

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

要将搜索范围限制在extra_content内的元素:

To limit the search to elements within extra_content:

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

这篇关于jQuery查找以字符串开头的所有ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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