Joann
Joann

Reputation: 1377

Add src attribute to iframe using jQuery?

$(document).ready(function(){
   $("#container").click(function(){
      $("#myiframe").attr('src', 'example.com');
   });
});

This doesn't work? The container is actually is a lightbox. The reason I am not defining the src attribute by default is because iframe loads even when lightbox isn't shown yet.

Upvotes: 1

Views: 6232

Answers (1)

Bob Fincheimer
Bob Fincheimer

Reputation: 18056

try:

$("#myiframe").get(0).contentWindow.location.href = 'example.com';

I think setting src isn't going to do anything after page load.

Upvotes: 4

Related Questions