EDIT:The problem is i am using react so i cannot wrap these elements using another div because they have many parents. Is there any way to look every div in the page which have class .my-class and show last instance of it.
I want to change the background color of the last div instance. In code div which contains 'third'.
https://jsfiddle.net/a694du2h/
But the first div becomes red too. I know it is because they do not have the same parent. Is there any way to do what I want?
<html>
<head>
<style>
.my-class:last-of-type {
background: #ff0000;
}
</style>
</head>
<body>
<div>
<div class='my-class'>first</div>
</div>
<div class='my-class'>second</div>
<div class='my-class'>third</div>
</body>
</html>