I’m adding a table dynamically to JQuery MObile UK
Table goes on like this
<table><TR><TD><a href="#" id="ClickedMe"></a><TD></TR></table>
Table then apended in to he HTML
Later I try to bind a click event like this
$('#ClickedMe').bind('click', function(e){
alert("hello");
});
But the alert never gets triggered.
====update===
this is how the table dynamically apended into a string
cust = cust + "<table id='cusTable'><tr><td scope='row'>" + getLocalizeLbl("phone") + ":</td><td>" + c.PhoneNo + "</td>";
cust = cust + "</tr><tr><td scope='row'>" + getLocalizeLbl("fax") + ":</td><td>" + c.Fax + "</td>";
cust = cust + "</tr><tr><td rowspan='1'></td></tr><tr><td scope='row'>" + getLocalizeLbl("contact") + ":</td><td><a href='contacts.html' rel='external'>" + dc.Name + "</a></td>";
sessionStorage.ContactID=dc.ID;
cust = cust + "</tr><tr><td scope='row'>" + getLocalizeLbl("email") + ":</td><td>" + dc.Email + "</td>";
cust = cust + "</tr><tr><td scope='row'>" + getLocalizeLbl("direct") + ":</td><td>" + dc.Direct + "</td>";
cust = cust + "</tr><tr><td scope='row'>" + getLocalizeLbl("mobile") + ":</td><td>"+ dc.Mobile + "</td></tr>";
cust = cust + "</tr><tr><td scope='row'>" + 'Bill to Cust' + ":</td><td><a href='#' id='ClickedMe'>333343</a></td></tr></table>"
and I try to place the function as given in the all answers inside the pagecreate event but still no luck. Why this alert is not getting triggered??
The code you’re after is:
But that doesn’t make sense. The selector is for
idand id must be unique!. So when you add the new#ClickMeelement attach it the click callback.Read the docs (Though it’s couple of paragraphs to read…):