Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access parent.document elements using JQuery in firefox?

Tags:

jquery

firefox

For example:

$(elementid,top.document).attr(attributeName) 

or

$(elementid,parent.document).attr(attributeName) 

works in IE or Chrome but doesn't work in Firefox.

Does anyone know what the firefox equivalence is?

Thanks!

like image 484
Ke. Avatar asked Jul 15 '09 18:07

Ke.


People also ask

Can iframe access parents?

When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.

How do I find a specific parent in jQuery?

jQuery parent() Method The parent() method returns the direct parent element of the selected element. The DOM tree: This method only traverse a single level up the DOM tree.

How do I get iframe from parent file?

To access elements of parent window from iframe with JavaScript, we can use the window. parent. document property to get the parent window's document.

Can you use jQuery on an iframe?

You can use jQuery to add jQuery effects to your iFrame elements, to change the CSS rules, or even to add content. Above, the script is used to change the background color of the . page element within the frame to white.


2 Answers

What about:

window.parent.$(elementid).attr(attributeName); 
like image 81
DLS Avatar answered Oct 05 '22 11:10

DLS


Try this:

$("#myid", top.document);  

or

$("#myid", parent.document.body);  

Ref

like image 33
Mahdi Avatar answered Oct 05 '22 11:10

Mahdi