1

I have a popover with html:true; I want to click on an element in the title, to close the popover, but it does not seem to do the job.

test fiddle http://jsfiddle.net/9P64a/1362/

Siguza
  • 21,155
  • 6
  • 52
  • 89
aVC
  • 2,254
  • 2
  • 24
  • 46
  • I have seen your jsFiddle Demo - It seems there are some issue with your HTML syntax. See the update jsFiddle - http://jsfiddle.net/chintansoni/9P64a/1364/ – prog1011 Nov 19 '14 at 07:17
  • Thats not what I want. Can you tell me, what is wrong with the html syntax? It works just fine for me. Also, with jquery 1.8 and .live, this will work. But I want to move on to newer versions, and .on – aVC Nov 19 '14 at 07:20
  • 1
    @Prog There is nothing wrong with the HTML syntax. He's passing in HTML mark-up to an element's custom attribute – Lloyd Banks Nov 19 '14 at 07:37

2 Answers2

1

Bootstrap dynamically creates and deletes the popover element ever time the element appears / disappears (as opposed to showing and hiding an element that is only created once). To account for this, you need to list the parent container when you use jQuery's .on() method.

Change

$('#btncancel').on("click",function()

to

$('body').on('click', '#btncancel', function()

The above looks for the element #btncancel within the HTML body element and will do so even if #btncancel is created / deleted / recreated on the DOM.

Example

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
0

What version of jquery you are using??

In your fiddle

$('#popoverData').popover({ html: true });
$('#btncancel').live("click",function(){
    $('#popoverData').popover('hide');
});

I used live() for generated pages and frames. But in jQuery 1.9 this function is deprecated and does not work.

Already answered here Turning live() into on() in jQuery

Update

$('#popoverData').popover({ html: true });
$(document).on("click", '#btncancel', function () {
   $('#popoverData').popover('hide');
} );
Community
  • 1
  • 1
Miomir Dancevic
  • 6,726
  • 15
  • 74
  • 142
  • I am using 1.11.1. Live is not working there. I do use .on, but that is not working either. – aVC Nov 19 '14 at 07:09
  • This one, with 1.8.3 and .live, it works. Yes. But not with a newer version and .on – aVC Nov 19 '14 at 07:29
  • Thanks, Gorostas, I saw your answer. log was not showing "heat" in console. I tried changing jquery versions, but to no avail. But thanks again. it did give me some ideas. – aVC Nov 19 '14 at 07:42