I was wondering if there is a way to to detect where the cursor is currently focused in a textarea.

I'm currently using this method to add HTML line breaks:

document.forms[0].elements[2].value = document.forms[0].elements[2].value + '<br>';

But this will obviously just add the BR tags at the end of the text. Thanks in advance.