Adding a row to a table in iFrame using jQuery (live?)

I have a page loading an iFrame that has a source based on which link the user clicks on. The IFrame returns a small table in which I need to add a row.

My problem is that I need to use something like .live or .delegate, since the iFrame does not load on document.ready. How to associate .append with .live or .delegate on an iFrame load, rather than a click or mouse function?

I tried:

$(document).ready(function(){
    $('#click').click(function(){
        $('#myFrame').attr('src', 'http://iframe_link_here/');
    });

// Add the new row
$('<tr><td>New Row</td><td>goes here</td></tr>').appendTo('#myTable');
});

but since the table is not in the .ready document, and since I want to add this line to the iFrame load and just don’t know how to attach it.

Thanks for any help.

0
source share
1 answer

Just an idea:

$(document).ready(function(){
    $('#click').click(function(){
        $('#myFrame').attr('src', 'http://iframe_link_here/');
    });

   $('#myFrame').on('load',function(){
      // Add the new row
      $('<tr><td>New Row</td><td>goes here</td></tr>').appendTo('#myTable');
   });

});

EDIT: .live() , .on().

0

Source: https://habr.com/ru/post/1741357/


All Articles