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

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -