Add tooltip, whose value is same as span value
If I have <span>some text</span>
, how can I have this:
<span ti开发者_StackOverflowtle="*whatever is between span tags:* some text (in this case)">some text</span>
If you're building that HTML yourself, then just add the text into a title attribute at the time you're generating the html. e.g, in PHP it would be:
$text = 'some text';
<span title="<?php echo htmlspecialchars($text) ?>"><?php echo $text ?></span>
if you're doing it after the fact via Javascript, then (using jquery):
$('span').each(function () {
this.attr('title', this.text());
});
$("span[title]").each(function(){$(this).attr("title",$(this).text())});
That's how I'd do it.
http://jsfiddle.net/SYkEK/
精彩评论