jQuery – :contains() Selector

The jQuery contains selector select all elements that contain the specified text. The text must have matching case to be selected.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<h4>Hello World.</h4>
<h4>Hello World!!!</h4>
<h4>Underworld</h4>
<button>Click Here</button>

  
<script>
jQuery("button").click(function () {
	jQuery("h4:contains('World')").css("border","2px solid #1E8CBE");
});
</script>
</body>
</html>

Demo

Following example finds all H4 elements containing ‘World’ and create a border around them.

Hello World.

Hello World!!!

Underworld

,

No comments yet.

Leave a Reply