简体   繁体   English

jQuery单击功能不适用于弹出框内的按钮

[英]Jquery click function not working for the button inside popover

I am trying to alert an message when clicked on button with id tagit . 当我单击ID为tagit按钮时,我想提醒一条消息。 but the whole form is appearing in the bootstrap popover. 但是整个表单显示在引导弹出窗口中。 i also added the jquery for alerting message,but its not showing any alert dialog boxes,but when i call the same thing in javascript it is showing the alert. 我还添加了用于警告消息的jquery,但是它没有显示任何警告对话框,但是当我在javascript中调用同一件事时,它正在显示警告。 but i need it to be in jquery. 但我需要它在jQuery中。 how can i do this? 我怎样才能做到这一点?

var htmlcont ='<table class="pop-table"><tr><td><button class="btn btn-warning" id="tagit">FILTER</button></td></tr></table>';

$('[data-toggle="popover"]').popover({content: htmlcont, html: true});    

$("#tagit").click(function(){
      alert("hello this is working");           
});

You need to use event delegation , like so 您需要像这样使用event delegation

$(document).on('click', "#tagit", function() {
   console.log("hello this is working");           
});

Event delegation for dynamic created DOM elements. 动态创建的DOM元素的事件委托 Try to use Immediate parent selector to traverse easily and quickly 尝试使用立即父选择器轻松快速地遍历

$(document).on('click', '#tagit', function() {

}): 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM