Reputation: 7404
I want to set focus into my text area. Following is my code:
$this.textInput.val('').show().focus();
But it is not working. Actually when I press mouse button it appeared but when I mouseup it remove from text area. So after lot of searching I found setTimout method like :
$this.textInput.mouseover(function(){
setTimeout($this.focus(),0);
});
But still its not working in firefox. I have the latest 13.0 version but still it containing the problem but google chrome it is working properly. What's the problem with firefox is there any solution for it.
Thanks in advance.
Upvotes: 4
Views: 5710
Reputation: 291
Not all elements are focusable but default, there is a tabindex attribute to fix that.
When you assign tabindex=<number>
to an element:
It becomes focusable.
A user can use the tab key to move from the element with lesser positive tabindex to the next one. The exception is a special value tabindex="0"
means that the element will always be last.
The tabindex=-1
means that an element becomes focusable, but the tab key will always skip it. Only the focus()
method will work
Upvotes: 0
Reputation: 1524
Use .trigger('focus')
. I find it sometimes works better than .focus()
.
Upvotes: 4
Reputation: 7404
Try this :
$('#textareaid').click(function(){
$(this).after('focused?');
el = $(this);
setTimeout(function(){
el.trigger('focus')
},1);
})
Use .click method. I'll work for you.
Upvotes: 2
Reputation: 287
$this does not mean anything. You should use $(this) or you can set a variable like this-
var $this=$(this)
Upvotes: 0