Using Tooltip with img alt attribute
I want Tooltip to display my img tags' alt attribute text.
I am a newcomer to jQuery and jQuery UI so I am still on the steepest portion of the learning curve.
The UI Tooltip API provides an example of how to change from the default attribute ('title') to the img alt attribute. In doing so it shows how to use the Tooltip items option (
http://api.jqueryui.com/tooltip/#option-items). It also states, "
When changing this option, you likely need to also change the content
option." However, the content option (
http://api.jqueryui.com/tooltip/#option-content) code example only shows how to use a string for the Tooltip content, there is no example for using the function callback feature. It would be nice if the API were complimentary/consistent in nature, i.e. if it depicts an option example where another option is needed, that option should also depict an example based on the former example.
This was my solution...
<script>
$(function () {
$(document).tooltip({ items: "img[alt]",
content: function () { return $(this).attr("alt") }
});
});
</script>