Ivar
Ivar

Reputation: 4392

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 "legal" 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?

Upvotes: 1

Views: 630

Answers (2)

Lex
Lex

Reputation: 1378

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/

Upvotes: 2

BoltClock
BoltClock

Reputation: 723598

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.

Upvotes: 2

Related Questions