1

I want to add markup to the the iframe's body tag. Following code can do it but only if iframe content object is inside of click event. Here's example:

$(document).ready( function() {

    var tinymceFrame = $('#editor_ifr').contents().find('#tinymce');

    $('body').on('click', 'button', function() {
        $(tinymceFrame).append('<img class="widgetty" title="Widget" src="" />');
    });
});

This won't work but if I move tinymceFrame line inside click event it will work.

Also after image is added to iframe's body tag how to trigger on click event on that image? I tried something like:

$(tinymceFrame).on('click', '.widgetty', function() {
    alert('test');
});
marcin_koss
  • 5,763
  • 10
  • 46
  • 65
  • 1
    I think, *think*, this is because the content of the iframe is not loaded yet. See http://stackoverflow.com/questions/205087/jquery-ready-in-a-dynamically-inserted-iframe – Nivas May 15 '12 at 01:40
  • Thank you, following answer by David Valentiate helped solving the problem. – marcin_koss May 15 '12 at 02:01

0 Answers0