jQuery inside an iframe

I recently stumbled upon a little problem with an iframe. I tried finding some elements with jquery, but for some reason it can’t find inside an iframe. That’s why they (iframe developers) invented this method:

contents()!

http://api.jquery.com/contents/

I quote:

Given a jQuery object that represents a set of DOM elements, the .contents() method allows us to search through the immediate children of these elements in the DOM tree and construct a new jQuery object from the matching elements. The .contents() and .children() methods are similar, except that the former includes text nodes as well as HTML elements in the resulting jQuery object.

The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.

Voila!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s