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开发者_JS百科
you can do it by
if ($("#id").is(":focus")) {
alert('focus');
}
Its much easier to check by using jquery. Using jquery u can do it like this
if($"#div/inputtocheck").is(":focus"))
{
//do something u want if it is in focus
}
The :focus
returns true if the div is in foucs and false if it is not in focus
You can use document.activeElement.
精彩评论