Defining where jquery looks for element
What's the way to tell the jquery function where to look for the specified element. I call this script from an iframe.
<script type="text/javascrip开发者_如何学JAVAt">
$(document).ready(function() {
$('#tnav').load('loadtree.php');
});
</script>
The #tnav is a div located in the top page. The iframe doesn't know about the top page. So nothing happens when the script is printed out in the iframe source. What is the way to make the script load the div in the top page.
Thanks.
I believe you could use something like the following, to get the parent of the iframe and then specify the selector:
window.parent().$('#tnav').load('loadtree.php');
You can also use the context selector as shown below:
$('#tnav', parent.document).load('loadtree.php');
That will select the div (#tnav
) from the iframe's parent document (parent.document
)
General Syntax:
$('[item to select]',context);
When I changed the div in the top page to an iframe, this worked for refreshing the iframe.
<script type="text/javascript">
$(document).ready(function() {
treload = window.parent.document.getElementById('tnav');
treload.src = "loadtreeb.php";
});
</script>
精彩评论