开发者

Replace an element title box?

Is it possible to replace/disable the title box in an HTML element, so I could create my own with the title value in it?

If not: In case of the standard principle, is it "l开发者_如何转开发egal" to use an own attribute on an element to accomplish this? Or should I rather store the title value outside the element, in a JavaScript array for example?


You can write a script that searches for certain elements with the title attribute, remove the title attribute from said elements and replace it with custom HTML elements containing the title text that appear on hover.

There are plenty of jQuery tooltip plugins out there that do this, see for example qTip.


function showTitle()
{
    var offset = $('#d').offset();
    $('#title').css('left', offset.left+'px');
    $('#title').css('top', (offset.top-10)+'px');
    $('#title').text($('#d').attr('title'));
    $('#title').show();
}
function hideTitle()
{
    $('#title').hide();
}

$('#d').attr('title', 'Changed');
$('#d').hover(showTitle, hideTitle);

http://www.jsfiddle.net/lex_rwx/sj9B4/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜