开发者

Add tooltip, whose value is same as span value

开发者 https://www.devze.com 2023-03-25 06:29 出处:网络
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

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号