1

In my application I want to remove div content and add iframe, here is my code

index.html

<div data-role="page">
    <div data-role="header" >
    <div data-role="content" id="contents">
        <a href="#" data-role="button" onclick="cif()"><img src="images/zo_connect.png"></a>
        </div>

    </div><!-- /content -->
</div><!-- /page -->

default.js function cif(){

$("#contents").remove();
$("#contents").html('<iframe src="http://google.com" style="height: 100%; width: 100%"></iframe>');

}

when i remove div contents and after that create iframe it doesn't show, I need that after clicking button remove the contents and after that in that contents create iframe

2 Answers 2

3

Well if you remove "contents", it's gone... You can't thereafter change its html(), since it's gone. You might want to skip the first line altogether.

3

$('#contents").remove() removes the whole <div id='contents'></div>

You're looking for $('#contents").empty(), which will remove everything inside the <div id='contents'>

1
  • .html() calls .empty() (if necessary) so there is no need for that
    – Esailija
    May 26, 2012 at 12:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.