onlycode.org

javascript
jquery
html
css
angularjs
node.js
ajax
html5
php
json
arrays
google-chrome
dom
regex
reactjs
ecmascript-6
javascript-events

your's history:
using jquery to test if...

Using jQuery to test if an input has focus, just only code

jquery-on | javascript-events | jquery | javascript

edit
jQuery.expr[':'].focus = function( elem ) {
  return elem === document.activeElement && ( elem.type || elem.href );
};
if ($("...").is(":focus")) {
  ...
}
$("input:focus").doStuff();
$(document.activeElement)
(function ( $ ) {
    var filters = $.expr[":"];
    if ( !filters.focus ) { 
        filters.focus = function( elem ) {
           return elem === document.activeElement && ( elem.type || elem.href );
        };
    }
})( jQuery );

38
gnarf, 01.01.1970 03:00




edit
.focus {
    border-color:red;
}
  $(document).ready(function() {

    $('input').blur(function() {
        $('input').removeClass("focus");
      })
      .focus(function() {
        $(this).addClass("focus")
      });
  });

37
jbutler483, 09.06.2009 00:41




edit
jQuery.expr[':'].focus = function(elem) {
  return elem === document.activeElement && (elem.type || elem.href);
};

36
Mathias Bynens, 22.03.2011 14:58




edit
$('input').on("focus", function(){
   //do some stuff
});

35
jbutler483, 07.04.2015 18:27



edit
$('div').each(function(){

    var childInputHasFocus = false;

    $(this).hover(function(){
        if (childInputHasFocus) {
            // do something
        } else { }
    }, function() {
        if (childInputHasFocus) {
            // do something
        } else { }
    });

    $('input', this)
        .focus(function(){
            childInputHasFocus = true;
        })
        .blur(function(){
            childInputHasFocus = false;
        });
});

19
James, 09.06.2009 00:37




edit
$("...").mouseover(function ()
{
    // store state on element
}).mouseout(function ()
{
    // remove stored state on element
});

28
roosteronacid, 09.06.2009 14:30




edit
$('input').each(function(){
   if ($(this) == $.focused()) {
      $(this).addClass('focused');
   }
})

23
Murat Çorlu, 12.11.2009 11:05




edit
if(!$("#quotebox").is(".boxhasfocus")) $(this).removeClass("box_border");

20
Drew Gaynor, 09.06.2009 00:41

Add your just only code

your name:    



If you need full text click here

Some similar links Using jQuery to test if an input has focus ↓:
/ jQuery: Test if window has focus

Detect which form input has focus using JavaScript or jQuery

How to focus an input field on Android browser through javascript or jquery

Set mouse focus and move cursor to end of input using jQuery



This project is created for those who just need only code, wihout maaaaaaaaaaany words.