To find the last span of div and apply some changes in this using JQuery, we can use :last-child selector for this, like :-
$("div span:last-child" ).css({ color:"red" }); //apply css on last span of div
We can also use it for any element to find its last ,like if we want last paragraph in body then-
$("p:last-child").css("background-color", "yellow");
Above code will select last paragraph in body or in any element.
Complete example for div last span is :-
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<head>
<style>
span , p {
border: 2px solid green
}
</style>
</head>
<body>
<div style="border:1px solid; width:30%"><span>span 1</span><span>span2</span></div>
<span>second paragraph</span>
<p><span>third paragraph</span><a href="page1.html">go to page1</a></p>
<button id='action'>Click to Perform Action</button>
<script>
$('#action').click(function() {
$("div span:last-child" ).css({ color:"red" }); //apply css on last span of div
$('div span:last-child').text('last span text of div is changed');// change text of last span of div
});
</script>
</body>
</html>
Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
ReplyDeletePerl Certification Course in Chennai
Node JS Training Institutes in chennai
Swift Programming Training In Mumbai
ReplyDeleteSwift Developer Training In Ahmedabad
Swift Developer Training In Kochi
Swift Developer Training In Trivandrum
Swift Programming Training In Kolkata
Wonderful Blog post!!! I am more impressed with your data.
ReplyDeleteWhy Pointers are not Used in Java
Why Java Doesn't Support Pointers
This is really nice blog thanks for sharing this information.
ReplyDeleteAngularjs Training in Chennai
Angularjs Online Course"
Angularjs Training in Chennai
Great Post with valuable information. I am glad that I have visited this site. Share more updates.
ReplyDeleteIELTS Coaching in T Nagar
IELTS Coaching in Velachery
ReplyDeleteThank you, This was the best and most interesting course. please continue to share your thoughts.
RPA Course in Chennai
RPA Online Course
RPA Course In Bangalore
kralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
Q4UOX
عزل اسطح القطيف
ReplyDeleteIMFywNfhMH
شركة عزل اسطح بجازان
ReplyDeletetgDclAlPat