jQuery Selector .class

Introduction

The .class selector selects all elements with the specific class defined in class attribute of an HTML element.

$(".class")
Parameter Optional Description
class Required. Specifies the class of the elements to select

Select all elements with class "intro":

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(){
  $(".intro").css("background-color","yellow");
});//from   w w w. ja va  2  s  . com
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p class="intro">This is a test.</p>
<p>I am from java2s.com.</p>

<div class="intro">My name is Dolly.</div>
<p>I am from java2s.com.</p>

</body>
</html>



PreviousNext

Related