开发者

jQuery How do I focus on contents of iframe after clearing

开发者 https://www.devze.com 2022-12-22 18:22 出处:网络
I currently have a wysiwyg iframe where the user can submit input to another area on the page. Once the iframe input is submitted, I set it to clear the content. I want to also automatically focus bac

I currently have a wysiwyg iframe where the user can submit input to another area on the page. Once the iframe input is submitted, I set it to clear the content. I want to also automatically focus back in开发者_C百科to the iframe.

This is the code I currently have:

postContentClr = $("iframe#textarea1IFrame").contents().find("body")
postContentClr.html(" ").focus();


Figured it out. I had to simply focus on the parent. And Jitter is correct, since I already declared it as a jQuery object, it needn't be wrapped.

Working code:

postContentClr = $("iframe#textarea1IFrame").contents().find("body")
postContentClr.html("").parent().focus();


I'm not sure I understand what you are trying to do, but postContentClr is a jQuery object, so calling html() requires that you access it via jQuery like so:

$(postContentClr).html('').focus();
0

精彩评论

暂无评论...
验证码 换一张
取 消