check if <input> or <textarea> has the focus


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. window.onload = function() {
  2. for (i=0; i<form.elements.length-1; i++) {
  3. elem = document.forms['quick_reply'].elements[i];
  4. elem.focused = false;
  5. elem.hasFocus = function() {
  6. return this.focused;
  7. };
  8. elem.onfocus=function() {
  9. this.focused=true;
  10. };
  11. elem.onblur=function() {
  12. this.focused=false;
  13. };
  14. }
  15. }

URL: http://www.ozzu.com/programming-forum/using-javascript-check-the-focus-element-t76858.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.