4

I have an iFrame and a div with content in it. I want to delete the div via JavaScript, is that possible and how could I do that?

I don't want to just not display it (eg. display: none via CSS) but remove it from the HTML of the site. I have basic knowledge of JavaScript but don't have any experience working with an iFrame.

1

2 Answers 2

13

You can use

$("#iFrameId").contents().find("#yourDiv").empty();

It is better to use remove()

example: $("#iFrameId").contents().find("#yourDiv").remove();

Explanation

empty() will remove all the contents of the selection.

remove() will remove the selection and its contents and all the event handlers associated with it.

For reference:

  1. http://api.jquery.com/remove/
  2. http://api.jquery.com/empty/
Sign up to request clarification or add additional context in comments.

8 Comments

I understand it as it should be remove() not empty(), but i'm not sure what is expected behaviour
Yes, remove() is a better option than empty() in this case!! Thankzz!!
I have tried this and it worked for a normal "iframe" but not with a spreadshirt shop integration. You can view an example shop at: developer.spreadshirt.net/display/spreadShop/… scroll down at Out of the Box Shop Example. I just want to remove the footer, but when i use $("#footer").remove(); nothing happens.
When i try $("#footer").remove(); online at their site (developer.spreadshirt.net/display/spreadShop/…) it removes the footer. But not when i try it locally. I'm testing it locally but i'm online and i can't remove the footer. Is it because i test it "locally" or it's because of their script which is loading and maybe i have to execute the remove script after their script?
When i test the site local and than add the code in the firebug console i can remove the footer but when i try it in the HTML document i can't remove the footer. I've tested it live on my server and there's the same problem code written in the console no problem, code in html executed no chance to remove the footer. So what now? I've tried to combine the jquery .ready function but nothing. Why is the console approach working and not the code in the html?
|
0

You can try something like:-

frame.removeChild(//pass div id here);

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.