Reputation: 37
I need to obtain textarea id which was focused when i clicked another element.
I use $(':input:focus').attr('id')
, but after click textarea looses focus immideatly and I cann't obtain id of textarea was selected.
Could somebody help?
Upvotes: 1
Views: 1236
Reputation: 15603
Yes you can hold the id in a global variable to obtained it and one checked that currently which input type is focused.
Like it:
var areaId = $('textarea:focus').attr('id');
Either use above code or use below code:
var areaId = "";
//define this variable at the top of starting the javascript code.
areaId = $(':input:focus').attr('id');
Or you can use the focusout()
function of jQUery:
$(':input').focusout(function(){
var id = $(this).attr('id');
});
Upvotes: 1
Reputation: 1478
you can use .focusout()
method:
$('#focusedItem').focusout(function() {
var id = $(this).attr('id');
});
Upvotes: 0