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, I'm RJ! For more learnings about software and management, find me @rjzaworski or sign up for my semi-regular newsletter.

Let’s keep in touch

Send me timely updates on software, product, and process.