javascript - Load URL into iframe and find values of the HTML that was just loaded - Jquery -


i trying load url iframe doing following jquery code. problem when try find element of iframe loaded, returns content loaded in previous click. , first click null. can me around this? thanks

$(document).ready(function() {      $('.popup').click(function() {          $('#myiframe')                 .attr('src', $(this).attr('href'))                 .attr('frameborder', '0')          return false;     });     alert($('#myiframe').contents().find('.name').html()) }); 

you need wait the fetched url load iframe before can fetch contents it. can use the jquery .load() function this. this:

$(document).ready(function() {   $('.popup').click(function() {          $('#myiframe')                 .attr('src', $(this).attr('href'))                 .attr('frameborder', '0')                 .load(function() {                      alert($(this).contents().find('.name').html())                 })          return false;     });  }); 

Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -