javascript - Boostrap 3 popover dismiss not working as expected in latest version of bootstrap (3.3.5) -
i trying dismiss bootstrap 3 popover when user clicks anywhere on page besides popover. found excellent example on jsfiddle , added plain html file using latest version of bootstrap 3 (3.3.5).
in jsfiddle example works expected because using bootstrap version 3.0.2.
in application following happens:
i click button show popover, click outside of popover dismiss it. when click button show popover second time popover not open. if click button show popover again opens.
here in html file.
<!doctype html> <html> <head> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <title></title> </head> <body> <br/> <br/> <br/> <br/> <br/> <div class="bs-example tooltip-demo"> <div class="bs-example-tooltips"> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="top" data-content="vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">popover on top</button> <br/> <br/> <br/> <br/> <br/> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom" data-content="vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">popover on bottom</button> <br/> <br/> <br/> <br/> <br/> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="right" data-content="vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">popover on right</button> </div> </div> <script type="text/javascript"> $('[data-toggle="popover"]').popover(); $('body').on('click', function (e) { $('[data-toggle="popover"]').each(function () { //the 'is' buttons trigger popups //the 'has' icons within button triggers popup if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { $(this).popover('hide'); } }); }); </script> </body> </html>
Comments
Post a Comment