Posted By

dougunderscorenelson on 04/28/09


Tagged

form jquery focus field


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sulfurito
talbs


Adding a Focus class to Forms


 / Published in: jQuery
 

This adds a class to focused form elements (helpful for IE6/7), as well as adds a class to the input's parent (in this case, named "form-field").

  1. $("input, textarea", $("form")).focus(function(){
  2. $(this).addClass("focus");
  3. $(this).parents(".form-field").addClass("cur");
  4. });
  5. $("input, textarea", $("form")).blur(function(){
  6. $(this).removeClass("focus");
  7. $(this).parents(".form-field").removeClass("cur");
  8. });

Report this snippet  

You need to login to post a comment.