26
$(document).ready(function(){
    $('#button').click(function(){
       $('.accordion').load('<iframe src="google.com" frameborder="0" scrolling="no" id="myFrame"></iframe>');
    });
});

This can't display the iframe of google.com. Can anyone provide suggestions on how to fix it?

3
  • 1
    It obviously doesn't work - read the docs of the jQuery load function. Besides that, you have quoting issues in your code. Commented Nov 18, 2011 at 8:39
  • 2
    There is a syntax error in code around iframe src. ("google.com' - started with double quote, ends with single quote) Commented Nov 18, 2011 at 8:40
  • 1
    FYI: you can't iframe google that way Commented May 5, 2013 at 0:33

3 Answers 3

94

jQuery's load function isn't used this way. It takes a URL as a parameter, among others, and loads the response from that URL.

If you are trying to create an iframe DOM element, use the jQuery function to do this and append it where you want:

$('<iframe src="http://google.com" frameborder="0" scrolling="no" id="myFrame"></iframe>')
     .appendTo('.accordion');

or

$('<iframe>', {
   src: 'http://google.com',
   id:  'myFrame',
   frameborder: 0,
   scrolling: 'no'
   }).appendTo('.accordion');
Sign up to request clarification or add additional context in comments.

Comments

4

If .accordion is a container for your iframe try this instead:

$(document).ready(function(){
$('#button').click(function(){
   $('.accordion').html('<iframe src="google.com" frameborder="0" scrolling="no" id="myFrame"></iframe>');
});

});

And fix that quote syntax :)

Comments

0

2 errors.

  1. Use full path (not sure it's necessary)
  2. close google.com with double quotes.

    $('.accordion').load( '< iframe src="http://www.google.com" frameborder="0" scrolling="no" id="myFrame">');

(Ignore the space in iframe tag)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.