Adding a Focus class to Forms


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

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").


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.