I am trying to extract the id=obj1
from the string html_doc
and trying to attach an onclick function
to it
document.addEventListener("DOMContentLoaded",
function (event) {
$ajaxUtils.sendGetRequest("data/GOG123.json",
function (res) {
var residue=res.residues;
var html_doc = "<div>" + "<Button id = obj1>" + residue[0].index + "</Button> " + "</div>";
console.log(html_doc);
var html_doc2;
html_doc2= $("html_doc").find("obj1");
$(document).ready(function(){
html_doc2.click(function () {
alert("Hello!");
});
});
var div1=$("#infoDiv");
div1.append(html_doc);
}
);
});
It is not working (i.e not showing an alert message) neither it is throwing any error.
Can someone please help me with the same?
I referred to Why is this jQuery click function not working? but it did not work out for me.