jQuery first() get first from selected result

Description

jQuery first() get first from selected result

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(){
  $("p span").first().css("background-color", "yellow");
});/*from ww  w.j av a  2s. c om*/
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p>My <span>name</span> is CSS.</p>
<p>This is a <span>test</span>.</p>
<p>This <span>is</span> another test.</p>

</body>
</html>



PreviousNext

Related