Add a red color to first <p> element. - Javascript jQuery

Javascript examples for jQuery:Tag Traversing

Description

Add a red color to first <p> element.

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(){
    $("p").first().css("color", "red");
});// www.  j ava 2 s .c  o m
</script>
</head>
<body>

<p>First paragraph.</p>
<p>Second paragraph.</p>
<p>Third paragraph.</p>
<p>Last paragraph.</p>

</body>
</html>

Related Tutorials