Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Tooltip doesn't work if element is initially hidden

I have some buttons that show detailed information with Bootstrap tooltips. My main problem is that these buttons are initially hidden in a div (display:none;) and when the div is shown (display:block;) the tooltips don't work.

How can i overcome this issue?

like image 365
Ricky Avatar asked Aug 09 '26 05:08

Ricky


1 Answers

Ok, i figured out my problem...

I'm initializing bootstrap's tooltip in $(document).ready():

$(document).ready(function ()
{
    $(".bsTool").tooltip();
});

Everything ok, but... since i'm using UpdatePanels (ASP.NET) and my content is show/hidden via async postback, $(document).ready() doesn't get called!!!

In order to initialize the tooltip plugin on every async postback (and normal postbacks), i added it to a page load function:

function pageLoad()
{
    $(".bsTool").tooltip();
}

pageLoad() function is called by ASP.NET Ajax on the web page's first load, but also on each async postback. Therefore the tooltip plugin is registered again after the async postback.

Problem solved :)

like image 187
Ricky Avatar answered Aug 12 '26 08:08

Ricky