jQuery Selector #id

Introduction

The #id selector selects the element with the specific id from id attribute.

The id attribute must be unique within a document.

$("#id")
Parameter Optional Description
idRequired. the id of the element to select

Select the element with the id "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 ww.  j a  v  a 2  s  .c  o m
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

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

</body>
</html>



PreviousNext

Related