javascript - How to initialize bootstraps tooltip after including with ajax? -


i loading content (html) website ajax. includes, inter alia, snippet:

<a href="#" data-toggle="tooltip" title data-original-title="my tooltip text...">hover me...</a> 

as described here: bootstrap 3 > tooltip, need initialize it. how can initialize after ajax success? edit: full working example. here simulate "ajax call". problem duration. when delete timeout work:

<!doctype html>  <html lang="de">  	<head>  		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mtjoasx8j1au+a5wdvnpi2lkffwweaa8hdddjzlplegxhjvme1fgjwpgmkzs7" crossorigin="anonymous">  		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-flw2n01lmqjakbkx3l/m9eahuwpsfenvv63j5ezn3uzzapt0u7eysxmjqv+0en5r" crossorigin="anonymous">  	</head>	  	<body>  	  		<div id="html" style="margin-top: 50px;">  			that works: <a href="#" data-toggle="tooltip" title="" data-original-title="my tooltip 1 text">hover me 1...</a>  		</div>  		  		<div style="margin-top: 50px;">ajax: <span id="ajax"></span></div>      		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0msbjdehialfmubbqp6a4qrprq5ovfw37prr3j5elqxss1yvqotnepnhvp9aj7xs" crossorigin="anonymous"></script>  		<script type="text/javascript">  			// document ready  			$(document).ready(function ()  			{  				loadresult();  				activatetooltip();  			});    			// result  			function loadresult()  			{  				// "ajax call"			  				settimeout(function(){                      var result = '<a href="#" data-toggle="tooltip" title="" data-original-title="my tooltip 2 text">hover me 2...</a>';  					$("#ajax").html(result);  				}, 2000); // simulate ajax duration    				activatetooltip();  			}    			// tooltip  			function activatetooltip()  			{  				$('[data-toggle="tooltip"]').tooltip();  			}  		</script>    	</body>  </html>

https://plnkr.co/edit/kbsjk27f9sb5kv2ozy56

  <a href="#" data-toggle="tooltip" data-original-title="tooltip right works fine" data-placement="right">hover me...</a> 

and reactivate tooltip function in ajax success:

function loadresult() {     $.ajax({         type: "post",         url: "index.php?action=loadresult",         data: "id=1",         datatype: 'text',         success: function(data){             var json = $.parsejson(data);             $("#result").html(json.result);             activatetooltip();         }     }); } 

just add attribute: data-placement="right"


Comments