In jQuery, how do I get to the contents of an <object> #document <html> sequence?

I am injecting HTML code into a DIV via an <object> element.

I can navigate to the div that contains the content (div has id of "rhs_content") and I can see the contents in Chrome Dev Tools (F12):

 jquery
but I cannot figure out how to navigate to the stuff inside of the <object> element.  What is #document?  Can an .html page have 2 <html> tags?

I've tried:

$("html body #mainwrapper #righthandside #rhs_content #temp2 #document")
$("html body #mainwrapper #righthandside #rhs_content #temp2 #document html")

But the console always returns [  ]

Thank you for your help.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
#document looks like text - do you have a link?
0
Alexandre SimõesManager / Technology SpecialistCommented:
Ok so first things first, <object> elements are kind of like IFrames, they allow you to render other pages inside a page and still keep their own closed context.

Now for the code, the "trick" is to use .contents() method from jQuery:
$($('object').contents()).find('h2')

Open in new window

Althogh this is not enough :)
Just like IFrames, Objects have their own loading time so we can't query its contents before it actually received the content. To do that we must use the onload event like:
<object id="temp2" type="text/html" data="embeded.html" onload="onObjectLoad()"></object>

Open in new window


Here's a small plunker with a demo

Ah, about the #document, it's just the normal console representation of the window.document object.
If you want to test it, just go to the browser devtools console and type: document
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.