5

I use the code for bootstrap popover as follows,

<a href="javascript:void(0);" class="btn btn-primary btn-sm" rel="popover"  data-placement="top"
                        data-original-title="<i class='fa fa-fw fa-users'></i> Enter New Investor Group"
                        data-content="<div class='smart-form'><div class='col-sm-10'><label class='input'><input type='text' name='NewInvestor' placeholder='Investor Group Name' id='NewInvestor' /></label></div><div class='col-sm-2'><button id='btntest' class='btn btn-primary btn-sm assignedGroup' type='button' data-target-id='NewInvestor' >ADD</button></div></div><div class='clearfix'></div><br/>"
                        data-html="true">Add</a>

I would like to trigger a event on button click in jquery. Code as follows,

$("#btntest").click(function () {
        alert("You click on button");
    });

JSFiddle

What would be the reason my code is not working?

I will appreciate your help in advanced.

sridharnetha
  • 2,104
  • 8
  • 35
  • 69

3 Answers3

12

Assuming your code renders correctly, try the code below.

$(function(){
   $(document).on('click',"#btntest",function () {
      alert("test button clicked");
   });
});

Edited

Take a look at my JsFiddle and see if it works http://jsfiddle.net/jb5fexp3/

Nifal Munzir
  • 354
  • 1
  • 6
3

Check the Bootstrap documentation on popovers again:

<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">
    Click to toggle popover
</button>

and in your JS:

$(function () {
    $('[data-toggle="popover"]').popover()
})
Anuj
  • 1,474
  • 12
  • 23
1
$(document).on("click", "#btntest", function () {
 // your code`enter code here`
})`;`

will bind the event on the #btntest elements which are not present at the time of binding event example using ajax html data set.

Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38