I am trying to call a function from a dynamically generated button. However the click() function is not working when I click the link. Can't figure out why.
if ( hasCap === 'image' ) {
  caption = $(this).data('caption');
  link    = '<a href="#" style="float: right; margin-top: -10px;" class="hidecaption">Hide Caption</a>';
  return link + (caption ? caption + '<br />' : '') ;
}
  $( ".hidecaption" ).click(function() {
      alert( "target called" );
    });
 
     
    