jquery - Dynamically added button does not fire in Google Chrome Content Script -


my google chrome extension content script receives message popup.html using google chrome message passing api upon user logging in using popup.html.

the content script supposed dynamically add button page when clicked on trigger event handler.

the message received content script, button added, when clicked, button not fire handler.

code below (content script message receiver)

chrome.runtime.onmessage.addlistener(  function(request, sender, sendresponse) {      if (request.updatedom == "update") {           button = '<input title="buy now!" id="buynow"  type="submit">'           $(".button-link").before(button)      } }); 

content script buynow button click handler:

$("#buynow").on("click",function(e) {     console.log("button clicked")     alert("clicked button"); }) 

as button added dynamically used 'on' jquery event button added after page load thinking may work.

you need append handler exisiting element in dom or document

$(document).on("click","#buynow",function(e) {     console.log("button clicked")     alert("clicked button"); }) 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -