Rectify styles being cached permanently in issue 5827

Refer to #5827 to see issues that are arising.

This should overcome the potential for the conditional statement to return false when index = 0

Also incorporating #5832 having selection for incorrect pseudo-element.