Skip to content Skip to sidebar Skip to footer

Body Onclick Go To Textarea

This may not seem like a useful script, but I need something that will basically allow the user to click anywhere on the page and the cursor will go to the textarea. How I imagine

Solution 1:

Easy with jquery. But how useful, I don't know.

$('body').on('click', function(){
  $('textarea').focus();
});

Solution 2:

Vanilla JS:

document.onclick = function(){ document.getElementById('yourIDHere').focus(); }

Solution 3:

without jQuery (pure JS):

document.body.addEventListener('click', 
function(){
  document.getElementsByTagName('textarea')[0].focus();
});

Post a Comment for "Body Onclick Go To Textarea"