最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to delete HTML Elements in an iFrame using JavaScript - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Aug 4, 2015 at 12:05 SuperBiasedMan 9,96910 gold badges52 silver badges76 bronze badges asked Aug 4, 2015 at 11:33 adrinhoadrinho 791 gold badge1 silver badge4 bronze badges 1
  • 1 Have a look here: stackoverflow.com/questions/11658011/…. Also remember that you CANNOT modify the content of an iframe which exists on a different host / domain to the parent page - developer.mozilla.org/en-US/docs/Web/Security/… – nealio82 Commented Aug 4, 2015 at 11:37
Add a comment  | 

2 Answers 2

Reset to default 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/

You can try something like:-

frame.removeChild(//pass div id here);
发布评论

评论列表(0)

  1. 暂无评论