开发者

Load a Div from another page into another pages Div

开发者 https://www.devze.com 2023-03-02 04:41 出处:网络
I\'m trying to do this:开发者_开发知识库 Load content of a div on another page but it doesnt work for me. and I\'m not sure why.

I'm trying to do this:

开发者_开发知识库

Load content of a div on another page

but it doesnt work for me. and I'm not sure why.

what im wanting to do is, i have a mobile site im working with, and i want to pull the story content data thats on the main sites div, and place it on the mobile sites content div that way i dont have to really edit anything. whatever gets published on the main gets reflected on the mobile.

any ideas as to the best way to accomplish this? is there a way to do like an include in php or html but that it ONLY takes the targeted divs content and not everything else?


If I'm reading you correctly, this is what you need:

$('#result').load('ajax/test.html #container');

This will load the page ajax/test.html, grab the content of the element with id "container" and load this into your current pages' element with the id "result".

More info can be found at http://api.jquery.com/load/

Edit: Working code based on your test files:

<html>
    <head>
        <script src="http://code.jquery.com/jquery-git.js"></script>
        <script>
        $(document).ready(function(){
            $('#result').load('pull4m.shtml #hello');
        });
        </script>
    </head>
    <body>
        <div id="result"></div>
    </body>
</html>
0

精彩评论

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