programing

Jquery가 문자열로 시작하는 모든 ID를 찾습니까?

iphone6s 2023. 10. 14. 09:55
반응형

Jquery가 문자열로 시작하는 모든 ID를 찾습니까?

전체 페이지에서 "content_"로 시작하는 모든 ID를 검색하는 방법과 "extra_content"라는 이름의 디브에서만 찾을 수 있는 방법이 궁금했습니다.일단 내가 모든 아이디를 갖게 되면 나는 그것들을 숨기고 싶습니다.

아래는 제가 찾고 싶은 것에 대한 예시입니다.

<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>

예시가 도움이 될 것입니다.

감사해요.

selector와 함께 attribute-starts-with selector:

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

검색을 내의 요소로 제한하려면 다음과 같이 하십시오.extra_content:

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

언급URL : https://stackoverflow.com/questions/5616826/jquery-find-all-ids-starting-with-a-string

반응형