jQuery – ID Selector (“#id”)

The jQuery ID selector selects a single element with the given id attribute. Following code select an element with div1 id.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<div id="div1">Div 1</div>
<div>Div 2</div>

<button>Click Here</button>

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

Demo

Following example finds the element with the id “div1″ and create a border around it.

Div 1
Div 2

,

No comments yet.

Leave a Reply