.class Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:class

Description

The .class selector selects elements by class name.

Syntax

Parameter Description
class Required. class name to select

The following code shows how to select all elements with class "test":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".test").css("background-color","red");
});/*from w  w  w .  j av  a  2  s  . c o m*/
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p class="test">This is a test.</p>
<p>This is a paragraph.</p>

<div class="test1">This is a tag.</div>
<p>This is a paragraph.</p>

</body>
</html>

Related Tutorials