Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created September 11, 2011 19:18
Show Gist options
  • Save lsauer/1209992 to your computer and use it in GitHub Desktop.
Save lsauer/1209992 to your computer and use it in GitHub Desktop.
OnBlur will not fire when changing onFocus to onKeyUp, onKeyPress, onKeyDown,...
The following code will do just what you would expect (a css rule for the element's id is applied).
<input id="searchCmpnd" onClick="this._originalWidth = this.style.width; this.style.width='50%';" onBlur="this.style.width = this._originalWidth;" />
However when the onClick is changed to onKeyUp, onKeyPress, onKeyDown it will expand but not retract. This is because the element is not marked focused, or because the event order got messed up (in Chrome >12).
Include this.focus();
<input id="searchCmpnd" onClick="this._originalWidth = this.style.width; this.focus(); this.style.width='50%';" onBlur="this.style.width = this._originalWidth;" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment