4
How to perform a function when a <textarea>
is clicked?
4
How to perform a function when a <textarea>
is clicked?
6
To detect if a text field (textarea
) was clicked, with Javascript pure and unobtrusive, you can do:
HTML:
<textarea id="message"></textarea>
Javascript:
function $(id) {
return document.getElementById(id);
}
$('message').addEventListener('click', function () {
alert('You clicked on textarea.');
});
To view a demo, click here (jsFiddle).
Remembering that for events unobtrusive, a good practice is through addeventlistener.
If you want an option on jQuery, here it comes:
$('#message').on('click', function() {
alert('Hello!');
});
Noting that the HTML may be the same.
Please note that this javascript event bind needs to be called on Document.ready, end of the page or on window load.
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
I’m creating a chat, the sending part, reply to the person’s message, it’s all ready, it’s a very big code, then it’s complicated to post here
– user3081
You don’t need to post all the code, just the relevant snippets to your problem. That page has a better description of how to build your example.
– Gabe