The reason why document.querySelector('.parent:last-child') is returning null is because :last-child is a CSS pseudo-class that selects the last child element of its parent. It does not work with querySelector in the way you are trying to use it.
To select the last element with the class .parent, you can use document.querySelectorAll('.parent') to get all elements with that class, and then select the last one using array indexing. Here's an example:
const cards = document.querySelectorAll('.parent');
const lastCard = cards[cards.length - 1];
This will give you the last element with the class .parent.