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?
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');
});
you can use .focusout()
method:
$('#focusedItem').focusout(function() {
var id = $(this).attr('id');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.