Find an input label in jQuery

  • 5/4/2011

Find the label wrapping a user-input control

$.fn.findLabel = function() {

       var tags = {'input':1,'textarea':1,'select':1};

       if($(this).get(0).tagName.toLowerCase() in tags)
               return $('label[for=' $(this).attr('id') ']');
}

Hey, it's RJ—thanks for reading! If you enjoyed this post, would you be willing to share it on Twitter, Facebook, or LinkedIn?