simple plugin to get and cache a form elements label based on the for attribute
Download the production version or the development version.
In your web page:
<script src="jquery.js"></script>
<script src="dist/getLabel.min.js"></script>
...
<label for="input">label</label>
<div class="context">
<label for="input">context</label>
<input id="input" name="input">
</div>
...
<script>
jQuery(function($) {
// returns a jQuery object containing the first
// label found for the first matched element
$('#input')
.getLabel()
.text() // => "label"
;
$('#input')
.data('getLabel')
.$labels // => all labels linked to first match
;
$('#input')
.getLabel({
context: '.context'
})
.text() // => "context"
;
});
</script>
- added ability to set
getLabel({ context: '.closestParent' })
- initial release