I have a bit of jquery that makes an ajax request to a script and returns some json results. These results are then parsed and a little image gallery is created. This is then added to my form. That bit all works perfectly.... The problem I have is that I am trying to trigger an event to the images so that when you click an image I can do some more processing.... But I just cannot get the onclick to work...
If anyone has any pointers I would be very grateful.
$('.imgSel').click(function()
{
alert("I WORK!!!!");
});
$("#mydiv").change(function(){
{
var url = "ajax_pics.php";
$.ajax({
type: "GET",
url: url,
error: function(data){
console.log("could not get get pics");
},
success: function(data){
console.log(data);
var pics = jQuery.parseJSON( data );
$("#imageResultsDiv").remove();
var imageResults ='<label>Image</label><div id="currImg"></div>';
imageResults += "<div style='clear:both'></div><ul>";
imageResults += "<div id='imageResultsDiv'><ul>";
for(var i in pics)
{
imageResults +="<li>";
imageResults +="<img class='imgSel' id='"+pics[i].filename+"' src='"+pics[i].image+"' title='"+pics[i].summary+"'>";
imageResults +="<br/><small>"+pics[i].title+"</small>";
imageResults +="</li>";
}
imageResults +="</ul>";
$('#picsplaceholder').before(imageResults);
}
});
});