jQuery #id Selector


The #id selector in jQuery is used to select the element with the particular id.

Syntax

The syntax is as follows −

$("#id")

Example

Let us now see an example to implement the jQuery #id selector −

<!DOCTYPE html>
<html>
<head>
<style>
   .one {
      color: white;
      background-color: blue;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("#demo").addClass("one");
   });
</script>
</head>
<body>
<h1>Car Details</h1>
<p>Car: Chevrolet Equinox</p>
<p id="demo">4-link rear suspension</p>
<p id="demoone">Automatic Emergency Braking</p>
<p>Fuel Tank Capacity: Approx 14.9 gal</p>
</body>
</html>

Output

This will produce the following output −

Updated on: 11-Nov-2019

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements