#id Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:id

Description

The #id selector selects the element by id.

Syntax

Parameter Description
idRequired. id of the element to select

The following code shows how to select the element with the id "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 ww.j av a2  s . c o m*/
</script>
</head>
<body>

<p id="test">This is a test.</p>

<h1>Welcome to My Homepage</h1>

<p id="test">This is a test.</p>

<p>This is a paragraph.</p>

</body>
</html>

Related Tutorials