开发者

How to link to parent site (ie index.html) from a page that has been loaded into a div using .load()

开发者 https://www.devze.com 2023-02-21 14:51 出处:网络
This must be a quite common thing to do but I can\'t find any answers. Our parentdocument is called index.html.

This must be a quite common thing to do but I can't find any answers.

Our parent document is called index.html. In this document we have a button, and two divs.

One called #pitch, one called #header.

When button is pressed jQuery loads contact.html into #pitch. Something like this:

$(button).click(function() {
   $("#pitch").load("contact.html");
});

So far everything good. But now, how do I create a link inside contact.html (which now is the child) to #header which is inside the parent document?

ie:

$(SomeThingInContact.Html).click(function() {
   $("#header").text("new text");

});
</script>

UPDATE:

According to the answ开发者_开发百科ers yet maybe my questions has been unclear.

The problem is that the contact.html that is loaded into the div #pitch doesn't know about it's parent document index.html. But I want to make changes FROM contact.html TO #header which is in index.html

I've tried top.getElementById("header"). Also tried window.document.parent.getElementById.

Of what I understand these only work with iFrames, or?

Thanx


Try to find this guy before you use .text

$("#header").text("new text");

$("#header").find("#elementtofind").text("new text");
0

精彩评论

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

关注公众号