开发者

Jquery find all ids starting with a string?

开发者 https://www.devze.com 2023-02-23 20:15 出处:网络
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 t

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 e开发者_如何学JAVAxample 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.

Thanks


Use the attribute-starts-with selector:

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

To limit the search to elements within extra_content:

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

精彩评论

暂无评论...
验证码 换一张
取 消