Bind HTML attribute to high-lighted text

Bind HTML attribute to high-lighted text

Hello everyone!
 
I'm working on an interactive website where the user can change the font attributes of the text within the page they're reading.
 
Is there a way to bind, for example, bold tags around a snippet of text the user has high-lighted? What I mean (if that wasn't clear) is if the user is reading through the text on the page and drags their mouse over a piece of text then clicks a button and it turns bold, much like a rich text editor would work, is this possible to do?