Puppeteer querySelector Wildcard 옵션으로 찾기

wildcard로 attirbute value를 찾고자 할때 옵션을 간단히 설명한다.

<!DOCTYPE html> 
<html> 
	<head> 
	</head> 
	<body> 
		<h1>GeeksforGeeks</h1> 
		
		<!-- Since we have used * with str, all items with 
			str in them are selected -->
		<div class="str_first">The first div element.</div> 
		<div class="second">The second div element.</div> 
		<div class="my-strt">The third div element.</div> 
		<p class="mystr">Paragraph Text</p> 
	</body> 
</html>

위와 같은 Html이 있을경우

document.querySelectorAll( '[class*=str]' )

value에 str이 포함될경우를 찾는 것이다.

div 2개와 p 엘레멘트 까지 총 3개의 엘레멘트를 찾을수 있다.

document.querySelectorAll( '[class$=str]' )

$로 찾으면 str로 끝나는 엘레멘트를 찾게 된다.

p 1개를 찾을수 있다. <p class=”mystr”>

document.querySelectorAll( '[class^=str]' )

^로 찾게되면 str로 시작하는 엘레멘트를 리턴하게 된다.

div 1개를 찾을 수 있다. <div class=”str_first”>

This entry was posted in Javascript, nodejs. Bookmark the permalink.

Leave a comment