Display tooltip on Label's hover?
You can use the "title attribute" for label tag.
<label title="Hello This Will Have Some Value">Hello...</label>
If you need more control over the looks,
1 . try http://getbootstrap.com/javascript/#tooltips as shown below. But you will need to include bootstrap.
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Hello This Will Have Some Value">Hello...</button>
2 . try https://jqueryui.com/tooltip/. But you will need to include jQueryUI.
<script type="text/javascript">
$(document).ready(function(){
$(this).tooltip();
});
</script>
You don't have to use hidden field. Use "title" property. It will show browser default tooltip. You can then use jQuery plugin (like before mentioned bootstrap tooltip) to show custom formatted tooltip.
<label for="male" title="Hello This Will Have Some Value">Hello ...</label>
Hint: you can also use css to trim text, that does not fit into the box (text-overflow property). See http://jsfiddle.net/8eeHs/
Just set a title on the label:
<label for="male" title="Hello This Will Have Some Value">Hello...</label>
Using jQuery:
<label for="male" data-title="Language" />
<input type="hidden" name="Language" value="Hello This Will Have Some Value">
$("label").prop("title", function() {
return $("input[name='" + $(this).data("title") + "']").text();
});
If you can use CSS3, you can use the text-overflow: ellipsis;
to handle the ellipsis for you so all you need to do is copy the text from the label into the title attribute using jQuery:
HTML:
<label for="male">Hello This Will Have Some Value</label>
CSS:
label {
display: inline-block;
width: 50px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
jQuery:
$("label").prop("title", function() {
return $(this).text();
});
Example: http://jsfiddle.net/Xm8Xe/
Finally, if you need robust and cross-browser support, you could use the DotDotDot jQuery plugin.