jQuery – All Selector (“*”)

The All selector selects all elements. It finds every element (including head, body, etc) in the document. Following code selects all elements under #all-selector

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <div id="all-selector">
  <div>DIV Tag</div>

  <span>SPAN Tag</span>
  <h3>H3 Tag</h3>
  <p>P Tag</p>
  <button>Click Here</button>
  </div>
  <div>Div 2 Tag</div>
<script>
jQuery("button").click(function () {
	jQuery("#all-selector > *").css("border","2px solid #1E8CBE");
});
</script>
</body>
</html>

Demo

Following example finds every element in a div (having id=”all-selector”) and create a border around them.

DIV Tag

SPAN Tag

H3 Tag

P Tag

Div 2 Tag


,

No comments yet.

Leave a Reply