I would go for the first approach because it's faster and can apply on all the elements you want.
The easiest solution to modify DOM would be the UX manipulator widget. I think that should suffice for what you want to do.
If you'd like on the other hand to run your own code you can also use an HTML snippet widget. Just be careful if you choose to use the snippet, as javascript onLoad events can be temperamental with Mendix.