Changing title attribute using jQuery while element is hanging

I have a div button that has a title attribute that we used as text for tooltips using jQueryUI. I would like to change the button hint by clicking it. However, when the button is pressed and the callback function is running, the mouse is above the div and the title is null.

How can I fix this behavior? It seems that the jQueryUI Tooltip widget removes the title on hover and returns it back to the mouse.

$( document ).tooltip();
$(".btn").click(function(){
    alert($(this).attr("title")); // Expect to see T1 or T2 but shows blank
    if ($(this).attr("title")=="T1"){
        $(this).attr("title","T2")
    }else{
        $(this).attr("title","T1")
    }
});

Live: http://jsfiddle.net/lordloh/ckTjA/

Without the JQueryUI Tooltip widget in place, everything looks fine: http://jsfiddle.net/lordloh/ckTjA/1/

, , $(document). $(this).tooltip("option","content"), $(this). Javascript .

2013-02-18: $(document).tooltip("destroy");, $(document).tooltip();. :-( -, .

+5
3

title, . , , .

:

$("#my-element").data("ui-tooltip-title", "My new tooltip message");

, , .

, , , , . , :

$(".ui-tooltip-content").html($("#my-element").data("ui-tooltip-title"));

jQuery UI 1.10.0.

+3

API:

    $(this).tooltip('option', 'content', "New Content Goes Here");
+2

:

$('document'). ready (function() {$ ('document').tooltip(); $( "" ). (() {      ($ ().attr( "" ));     if ($ (this).attr( "title" ) == "T1" ) {         $ ().attr( "" , "2" );     } {         $ ().attr( "" , "1" );     }   }); });

$ ('document') should be in single or double quotes ('or "), and it works fine for me whitout $ (' document ') .tooltip ();
0
source

All Articles