You could even buy it at the close on the 5th with a 'market on close' order if your broker let you do that. I've done it, and received my dividends.
Anyway, I hope you know that price will go down as much as the dividend (not exactly, but in the average, it does).