Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input has focus or not using jquery [duplicate]

How to get input tag of html has focus or not using jquery

keydown event will work for form if input,image etc. tag has focus. but it will not work it focus is on form but not on any tags like input,image etc. How can I solve this. Please help Thanks in advance

$('#title').focusout(function() { if($(document.activeElement).is(":focus")) { alert('focus'); } else { alert('not focus'); } }); // this will not work

like image 660
Royal Pinto Avatar asked Jan 29 '26 04:01

Royal Pinto


1 Answers

you can do it by

if ($("#id").is(":focus")) {
  alert('focus');
}
like image 124
chhameed Avatar answered Jan 31 '26 19:01

chhameed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!