jQuery – Multiple Selector (“selector1, .. selectorN”)

The jQuery selects the combined results of all the specified selectors. Following code select multiple selector with combination of class and id.

Source Code

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

<button>Click Here</button>

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

Demo

Following example finds the elements that match any of the given selectors and create a border around them.

Div 1
Div 2

,

No comments yet.

Leave a Reply