Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Last active August 31, 2016 16:58
Show Gist options
  • Save ABM-Dan/7154d914c8b62fa9b029c987865cbb3a to your computer and use it in GitHub Desktop.
Save ABM-Dan/7154d914c8b62fa9b029c987865cbb3a to your computer and use it in GitHub Desktop.
(function($) {
return $.fn.extend({
findLabel: function() {
var matched;
matched = [];
this.each(function() {
var $label, $this, id;
$this = $(this);
id = $this.attr('id');
if (id != null) {
$label = $('label[for=\'' + id + '\']');
}
if (($label == null) || $label.length === 0) {
$label = $this.closest('label');
}
return matched.push($label);
});
return $(matched);
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment