jQuery Selector element, element, element

Introduction

The element selector can also be used to select multiple elements.

Seperate each element with a comma.

$("element1,element2,element3,...")
Parameter OptionalDescription
element Required.elements to be selected

Select all <h2>, <div> and <span> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("h2, div, span").css("background-color", "yellow");
});//www . j  av a 2  s. c o  m
</script>
</head>
<body>

<h1>Welcome to My Web Page</h1>
<h2>Nice to meet you</h2>

<div>Very nice indeed.</div>

<p>How are you?</p>
<p>I'm fine, <span>thanks.</span></p>

</body>
</html>



PreviousNext

Related