반응형

텍스트로 요소 찾기

 

jQuery: find element by text

Can anyone tell me if it's possible to find an element based on its content rather than by an id or class? I am attempting to find elements that don't have distinct classes or id's. (Then I then n...

stackoverflow.com

ID  클래스가 아닌 내용을 기반으로 요소를 찾을 수 있는지 누구든지 말할 수 있습니까 ?

고유 한 클래스 나 ID가없는 요소를 찾으려고합니다. (그런 다음 해당 요소의 부모를 찾아야합니다.)

 

Therefore it is not enough that you use :contains() selector, you also need to check if the text you search for is the direct content of the element you are targeting for, something like that:

따라서 :contains() selector 를 사용하는 것으로는 충분하지 않습니다. 검색하는 텍스트 가 대상 요소  직접 콘텐츠 인지 확인해야 합니다.

 

 

 Element에 포함된 텍스트(Text)로 객체를 찾아라!

function findElementByText(text) {
    var jSpot = $("b:contains(" + text + ")")
                .filter(function() { return $(this).children().length === 0;})
                .parent();  // because you asked the parent of that element

    return jSpot;
}

 * 아래 DIV   p-1 class 중에 텍스트가 3인 것을 찾아라. 

<div class="" id="pagenation" style="white-space: nowrap; overflow-x: hidden; width: 231px;">
<div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">1</div>
<div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">2</div>
<div class="p-1 paging-item border rounded text-center d-inline-block position-relative  style="width:33px;height:33px;">3</div>
<div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">4</div>
<div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">5</div><div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">6</div><div class="p-1 paging-item border rounded text-center d-inline-block position-relative" style="width:33px;height:33px;">7</div>
</div>


$(".p-1:contains('3')")
반응형

+ Recent posts