Hello Readers,
last() is the jquery method which is used to select or returns the last element of the selected elements or the matched elements in jquery.
Syntax :
$(selector).last()
In the above syntax there is no parameter inside last() method.
Code Example :
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div p").last().css("background-color", "yellow");
});
</script>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<div style="border:1px solid black">
<p>This is a paragraph in a div.</p>
<p>This is a paragraph in a div.</p>
</div><br>
<div style="border:1px solid black">
<p>This is a paragraph in another div.</p>
<p>This is a paragraph in another div.</p>
</div>
<p>This is also a paragraph.</p>
</body>
</html>
In the above code select the last paragraph p element inside the last div element in jquery.
0 Comment(s)