{"id":7873,"date":"2010-11-18T11:15:35","date_gmt":"2010-11-18T18:15:35","guid":{"rendered":"http:\/\/css-tricks.com\/"},"modified":"2010-11-18T11:15:35","modified_gmt":"2010-11-18T18:15:35","slug":"highlight-related-label-when-input-in-focus","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/jquery\/highlight-related-label-when-input-in-focus\/","title":{"rendered":"Highlight Related Label when Input in Focus"},"content":{"rendered":"
$(\"form :input\").focus(function() {\r\n  $(\"label[for='\" + this.id + \"']\").addClass(\"labelfocus\");\r\n}).blur(function() {\r\n  $(\"label\").removeClass(\"labelfocus\");\r\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

$(“form :input”).focus(function() { $(“label[for='” + this.id + “‘]”).addClass(“labelfocus”); }).blur(function() { $(“label”).removeClass(“labelfocus”); });<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3245,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":6241,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/click-input-when-label-clicked\/","url_meta":{"origin":7873,"position":0},"title":"Trigger Click on Input when Label is Clicked","date":"April 22, 2010","format":false,"excerpt":"Labels should have \"for\" attributes that match the ID of the input they are labeling. This means we can snag that attribute and use it in a selector to trigger a click on the input itself. Assuming of course you have some reason to watch for clicks on inputs. var\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14180,"url":"https:\/\/css-tricks.com\/almanac\/selectors\/e\/enabled\/","url_meta":{"origin":7873,"position":1},"title":":enabled","date":"April 18, 2013","format":false,"excerpt":"The :enabled pseudo-class in CSS selects focusable elements that are not disabled, and therefore enabled. It is only associated with form elements (,