Reputation: 555
hi i add a image inside the tr dynamically now i want to call a function when i click this image iuse this code
$("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").html(" <img src=\"Images/ExpandArrow.png\">" + OriginalContent)
$(document).on('click', 'image.ExpandArrow', function () {....});
but its not working
Upvotes: 2
Views: 45
Reputation: 974
It should be img.ExpandArrow
and not image.ExpandArrow
.
use this also $("#tabletask")
$("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").html(" <img src=\"Images/ExpandArrow.png\">" + OriginalContent)
$("#tabletask").on('click', 'img.ExpandArrow', function () {....});
Upvotes: 0
Reputation: 18657
Try giving a class to that image and try to bind the class to the document.
$("#tabletask tr[data-id='" + parrentid + "'] > td:first-child")
.html(" <img class = 'image' src=\"Images/ExpandArrow.png\">" + OriginalContent)
$(document).on('click', '.image', function () {....});
Upvotes: 0
Reputation: 9876
var img = $("<img>", {src: "/path/to/img"});
$("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").appendChild(img);
img.onclick = functionName;
where functionName
is the function you want to happen when it's clicked.
Upvotes: 1