2

json2html, I need to add click events to the resulting html after the transform. right now I am using a timer. Even though it did not appear to be an option i attempted to add the code to the Options for the transform call. Didn't work. Is there a better option than adding a timer to document.ready to give the transform time to run before adding my click event to the resulting divs?

setTimeout(function() {
  $('.item').click( function() {
    $this = $(this);
    $.fancybox({
      height: '100%',
      href: $this.find('a').attr('href'),
      type: 'iframe',
      width: '600px'
    });
    return false;
  });
}, 1000);
user3128573
  • 71
  • 1
  • 3

1 Answers1

2

this answer is coming a little late .. but hey better late than never.

You can directly assign events within json2html like so

json2html eventData example

OR you can just do it manually after you call the transform like so

$('#someElement).json2html(data,transform);

$('.item').click( function() {
   $this = $(this);
   $.fancybox({
      height: '100%',
      href: $this.find('a').attr('href'),
      type: 'iframe',
      width: '600px'
   });
   return false;
});
Community
  • 1
  • 1
Chad Brown
  • 1,627
  • 1
  • 13
  • 22