Select last span inside p element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:last

Description

Select last span inside 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 span").last().css("background-color", "yellow");
});//from  w w w .j  a  v a  2 s .c o m
</script>
</head>
<body>

<p>My <span>name</span> is span.</p>
<p>tutorial from <span>java2s.com</span>.</p>
<p>tutorial from <span><b>java2s.com</b></span>.</p>

</body>
</html>

Related Tutorials