简体   繁体   中英

Can you make a browser display an HTML title attribute after setting it dynamically?

I need to be able to show what would appear to be a tooltip when the user hovers over an element, but the text I need to display is only known after the user hovers, which triggers an ajax call to a server to get the text to be displayed, which I then set as the title attribute of the element.

Since there was no title attribute when the user began hovering over the element, no tooltip is displayed, even after I set the title. I have to mouse off the element and then back onto it before the tooltip appears.

Is there any way to force or fake the browser into displaying the tooltip after I've set the title attribute?

Using jquery .on( "mouseover", handler ) event you can add a span with .fadeIn()

You just have to make it look like a tooltip with css

Here are some bootstrap tooltip examples from w3schools bootstrap tool tip might help you,

<script>
    $(document).ready(function(){
        $('[data-toggle="tooltip"]').tooltip();   
    });
</script>

我遇到了同样的问题,最后,我使用了Bootstap的工具提示

$('#element').tooltip('show')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM