How to access embeded html document's children in parent html document

时间:2016-04-21 22:48:21

标签: javascript jquery html

Simple, what I want to do is to use jquery to select text from

<p class="oldtext">Hello world</p> to <p class="newtext"></p>

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="Ell" />

    <title>Trials</title>
    <script>
        $(document).ready(function(){

        }); //end ready
    </script>
</head>

<body>
<div>
    <p class="newtext"></p>
</div>
#document
<html>
    <head>

    </head>
    <body>
        <div>
            <p class="oldtext">Hello World</p>
        </div>
    </body>
</html>

</body>
</html>

Please how do I do that? Is it posible to do with JQuery or Javascript?

2 个答案:

答案 0 :(得分:1)

像这样,请参阅小提琴:https://jsfiddle.net/5wwg1q5j/57/

<p class="oldtext">Hello World</p>
<p class="newtext"></p>
<script>
var str = $( ".oldtext" ).text();
$('.newtext').text(str);
</script>

答案 1 :(得分:1)

您可能需要以下内容:

$(function(){
  $('.newtext').load('yourOtherPageURL.html .oldtext', function(){
    // do stuff after load
  });
});

当然,很难确定你想要对你不明确的问题做些什么。只是想帮忙。