I can't access dynamically created images by their id?!

I can't access dynamically created images by their id?!

I have a stupid problem that really bugs me...

The code below creates images based on a json feed, no problem. All images are created and the click function works perfectly, but... I can't access any of the images by their id's so I can't make the function behave as I wan't.

I first thought jQuery appended my image object as html and didn't insert it as a valid object in the dom, but as the click function is working that can't be it?

I found some other people had the same problem but they were using vanilla js, their solution was using .appendChild() but that doesn't work in jQuery.

I really hope someone can shed some light over my little issue, all input are very appreciated!
  1. $.each(json.hotgames, function(i, item) {
  2. var image = $('<img>')
  3. .attr('id', item.uuid+':'+item.lane)
  4. .attr('src', 'xxx')
  5. .click(function(){
  6. new Boxy('some html', {title: item.company_name});
  7. })
  8. .css('width', '179px')
  9. .css('cursor','pointer')
  10. .load(function() {
  11. arrHotGames.push('#'+item.uuid+':'+item.lane)
  12. if ($('#'+item.uuid+':'+item.lane).length == 0) {
  13. $('#hotGames').append($(image));
  14. } else {
  15. $('#'+item.uuid+':'+item.lane).replaceWith($(this));
  16. }
  17. });
  18. });