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

javascript - jQuery iFrame manipulation - Stack Overflow

programmeradmin1浏览0评论

I'm facing a problem while working with iFrames. What I need to do is, get the contents of a division 'contents' , display it in an iframe, and then remove all forms/form elements ONLY in that iframe. When i use $("#form").remove(), it removes the form both in iframe and in the window. Can someone help?

Thank You.

I'm facing a problem while working with iFrames. What I need to do is, get the contents of a division 'contents' , display it in an iframe, and then remove all forms/form elements ONLY in that iframe. When i use $("#form").remove(), it removes the form both in iframe and in the window. Can someone help?

Thank You.

Share Improve this question asked Jun 8, 2009 at 15:22 ChecksumChecksum 3,2403 gold badges24 silver badges25 bronze badges 1
  • My problem turned out to be slightly different from my original question, but daldaeb's solution works. – Checksum Commented Jun 9, 2009 at 15:22
Add a ment  | 

3 Answers 3

Reset to default 4

You can wrap the iframe in a DIV with an ID and remove forms only inside of that. Can you post some code? Would be easier to work off that. Or just grab the iframe (although I'm not sure it will work, haven't tested it).

$("iframe").find("#form").remove();

Do both the forms have the same id (#form)?

Give them separate ids (eg: <form id="inner"> and <form id="outer">) and you should be able to target them individually: $(#inner).remove()

I don't know it in jQuery but I think that this in strait javascript might help you.

var forms = document.getElementById('iframe_id').getElementsByTag('form')
for (var form in forms) {
    forms[form].parent.removeChild(forms[form])
}

Disclaimer: I havn't tested this code, but with some debugging it should work... eventually. I just put it here so you maybe can guess to what you need to to do.

Perhaps the jQuery (now I'm just guessing) that you need is something like:

$('iframe_id').('#form').remove()

Or maybe dlabaeb's code already posted.

发布评论

评论列表(0)

  1. 暂无评论