English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery Multiple Element Selectors

jQuery Selectors

You can select multiple selectors as needed. Just separate selectors with commas.

Multiple selectors select the combined result of all specified selectors.

This is very useful when you want to perform the same operation on different selectors.

Syntax:

$("selector1, selector2, selectorN)

Instance

Select each<p>and<h4>elements:</div>

$ (document).ready(function() {
  $("p, .h4").css("background-color", "lightgreen");
});
Test See‹/›

Select each<h2>,<div>and<span>elements:</div>

$ (document).ready(function() {
  $("h2, div, span").css("background-color", "lightgreen");
});
Test See‹/›

Select all elements with the multiple class names "demo" or "para":

$ (document).ready(function() {
  $(".demo, .para").css("background-color", "lightgreen");
});
Test See‹/›

Parameter Value

ParameterDescription
selector1, selector2,selectorNSpecify the selector to be chosen

jQuery Selectors