0

The code below works if the #client-result-0 id is set to a static element. But when I point it to a dynamically created element, it doesn't work. I am using jQuery 1.7.1.

$j('#client-result-0') .on('click','.myLi',function(){
    console.log('haha');
    $j('#client-search-0').val($(this).text());
});

Thanks

jean-max
  • 1,640
  • 1
  • 18
  • 33
  • 1
    Event is delegated to a static element, Since `#client-result-0` is dynamically generate it will not work. As you are aware set to a static element – Satpal Dec 12 '16 at 08:47
  • No, #client-result-0 is the static element. #client-result-1 and so on would be the dynamic elements. – ToldarkenHansam Dec 12 '16 at 08:48
  • The element you delegate to has to exist when the event is bound, commonly on page load. Hence if you create `#client-result-0` *after* page load then no event is bound. See the question I marked as duplicate for more information – Rory McCrossan Dec 12 '16 at 08:49

0 Answers0