반응형

텍스트로 요소 찾기

 

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')")
반응형
반응형

제가 살면서 겪은 모든 역경들, 그리고 모든 장애물과 고민들이
결과적으로는 저를 더 강하게 만들어주었습니다.
여러분도 그걸 겪을 때는 깨닫지 못하겠지만,
그 어떤 시련도 언젠가는 당신의 인생에서 최고의 일이 될 수 있습니다.
- 월트 디즈니


월트 디즈니의 또 다른 명언을 함께 보내드립니다.
“언젠가 저는 꿈이란 게 실현되기 위해 존재한다는 것을 깨닫게 되었습니다.
그래서 그날 이후론, 쉬기 위해 잠을 자는 것이 아니라,
꿈을 이루기 위해 잠을 잤습니다.”

반응형
반응형

인간의 몸에는
병에 걸리도록 설계된 프로그램은 없지만,
완벽한 평형 혹은 균형 상태를 유지하면서 균형이
무너졌을 때 다시 균형을 잡도록 하는 프로그램이
많다. 건강해지려는 것은 인간의 본성이지만
이러한 프로그램들이 효과적으로 작동하는
전제 조건을 충족시키는 것은
우리가 해야 할 일이다.


- 안드레아스 모리츠의《건강과 치유의 비밀》중에서 -


* 병에 걸리는 것도 '나'고
병을 이겨내는 것도 '나'입니다.
몸의 균형을 잃었을 때 병에 걸리고
몸의 균형을 다시 찾았을 때 병을 이겨낼 수
있습니다. 다른 사람이 대신할 수 있는 일이
아닙니다. 전적으로 나의 몫입니다.
완벽한 균형 상태 유지가
'나'를 살립니다.

반응형

'생활의 발견 > 아침편지' 카테고리의 다른 글

잠깐의 여유  (0) 2020.11.23
신입사원들의 '성급한 판단'  (0) 2020.11.20
'희망은 격렬하다'  (0) 2020.11.18
음악이 중풍 치료에도 좋은 이유  (0) 2020.11.17
세포 재생, 세포 파괴  (0) 2020.11.16

+ Recent posts