Reputation: 363
I got this code:
<textarea id="status" placeholder="Write here..." name="new_entry"></textarea>
and this:
$('#status').focus(function() {
alert('focused!');
});
I want the alert to start when the textarea is focused on, but it doesn't work...
Upvotes: 10
Views: 28026
Reputation: 1
try this instead :
$(function(){
$('#status').click(function() {
alert('focused!');
});
});
hope it'll help
Upvotes: -1
Reputation: 1070
If the text area which your are trying to bind focus to is loaded dynamically [using ajax or something], then you have to bind the live event of focus. Something like this
$('#status').live('focus', function() {
alert('focused!');
});
Upvotes: 2
Reputation: 2698
Your jquery is written correctly. See this similar fiddle. Check with a debugger (in Chrome or Firebug), is the focus
method being called? You can try putting the code in a $('document').ready()
function.
<textarea id="status" placeholder="Write here..." name="new_entry"></textarea>
<textarea id="status2" placeholder="Write here..." name="new_entry"></textarea>
$('#status').focus(function() {
$('#status2').val("wheee");
});
Upvotes: 0
Reputation: 73966
Try this:
$(function(){
$('#status').focus(function() {
alert('focused!');
});
});
Upvotes: 1
Reputation: 6365
HTML
<textarea id="status" placeholder="Write here..." name="new_entry"></textarea>
JS
$('document').ready(function(){
$('#status').focus(function() {
alert('focused!');
});
});
Upvotes: 3