Reputation: 265
I'm not JavaScript wizard, so I'm missing something obvious here I'm sure. I have a unorder-list that has multiple links & When user do hover on the <li>
then they can see the link to click on it in order to see Twitter Bootstrap's pop-over behavior
.
My problem is
pop-over
if i open a new one. Here is fiddle http://jsfiddle.net/ZnJ6b/17/ , please take a look & try to help me.
js code looks like
$("[data-toggle='popover']").popover({
placement: 'right',
html: 'true',
title : '<span class="text-info"><strong>title</strong></span>',
content : '<input id="subproject_id" type="text"/>'
});
$('.add_btn').click(function(e) {
$('.popover-title').append('<button id="popovercloseid" type="button" class="close">×</button>');
$("#subproject_id").focus();//textbox focus
$(this).css("display","inline");
$(this).removeClass( "add_btn" ).addClass( "new_add_btn" );
});
$(document).click(function(e) {
if(e.target.id=="popovercloseid" ) {
$('.new_add_btn').popover('hide');
$('.new_add_btn').css("display","none");
$('.new_add_btn').removeClass( "new_add_btn" ).addClass( "add_btn" );
}
});
http://blog.alysson.net/lang/pt-br/twitter-bootstrap-popover-close-all-before-opening-a-new-one/ is the link seems tutorial, but i am unable to implement it to above code. Any help please?
Upvotes: 4
Views: 2999
Reputation: 536
this actually fix the issue: $('.popover').each(function() { $(this).modal('hide'); });
Upvotes: 0
Reputation: 11665
Your code has some unnecessary lines that deflect the behavior of the popover.
I've commented some of the lines and added this statement:
$('.add_btn').not(this).popover('hide');
so that only one popover is displayed at a time.
This bit of code to close your popover with a button:
$('html').on('click', '#popovercloseid', function (e) {
$('.add_btn').not(this).popover('hide');
});
Upvotes: 7