How do I load an url in iframe with Jquery

Youss picture Youss · Aug 24, 2011 · Viewed 199.9k times · Source

I want to load an iframe on click, this is what I have so far:

$("#frame").click(function () { 
      $('this').load("http://www.google.com/");
    });

It doesn't work. This is the complete code: JS Bin

Answer

Dogbert picture Dogbert · Aug 24, 2011
$("#button").click(function () { 
    $("#frame").attr("src", "http://www.example.com/");
});

HTML:

 <div id="mydiv">
     <iframe id="frame" src="" width="100%" height="300">
     </iframe>
 </div>
 <button id="button">Load</button>