You might reassign the $write
variable when focussing another textarea, so that the keyboard always edits the one that was last focussed:
$('textarea').on('focus', function () {
$write = $(this)
})
You might want to also add a class to the currently active text area though so that the user can see which they are currently editing.
Do you want to just emulate the regular tab-key behaviour, or cycle through a given list of text areas (such as $('.write')
)?