문법
$(":contains(텍스트)")
특정 문자열을 포함한 요소를 선택하는 선택자
예를 들어
1. $("p:contains('Love')").css("color", "red");
2. $("p:contains('2002')").css("color", "blue");
1. Love 라는 문자가 포함된 p태그를 선택
2. 2002 라는 문자가 포함된 p태그를 선택
예제 코드
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<title>Home</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
$("p:contains('Love')").css("color", "red");
$("p:contains('2002')").css("color", "blue");
});
</script>
<body>
<p>I will always remember</p>
<p>The day you kissed my lips</p>
<p>Light as a feather</p>
<p>And it went just like this</p>
<p>No, it's never been better</p>
<p>Than the summer of 2002 (ooh)</p>
<p>Uh, we were only eleven</p>
<p>But acting like grown-ups</p>
<p>Like we are in the present</p>
<p>Drinking from plastic cups</p>
<p>Singing, "Love is forever and ever"</p>
<p>Well, I guess that was true</p>
<p>-2002가사-</p>
</body>
</html>
실행 테스트