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>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

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

jQuery("button").click(function () {
	jQuery("h4:contains('World')").css("border","2px solid #1E8CBE");


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

Hello World.

Hello World!!!



No comments yet.

Leave a Reply