jQuery – Element Selector (“element”)

The jQuery element selector selects all elements with the given tag name. Following code select div element under #element-selector

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<div id="element-selector">
  <div>DIV 1</div>
  <div>Div 2</div>
  <span>SPAN</span>
  <button>Click Here</button>
</div>  
  
<script>
jQuery("button").click(function () {
	jQuery("#element-selector > div").css("border","2px solid #1E8CBE");
});
</script>
</body>
</html>

Demo

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

DIV 1
Div 2

SPAN

,

No comments yet.

Leave a Reply