SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting HTML Content From Other Pages

    Good day everyone,

    I have a simple JQuery code.
    When a link is clicked, the HTML content is taken from a page(remotely) and placed in a specified area, like a div in another page.

    My question is, how do I add additional links to this script so that each link pulls HTML content from different divs?

    Here is a demo.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Practice Template</title>
    </head>
    
    <body>
    <div id="test">
    <p>I'm contents from the div in another HTML file!</p>
    <p>I will be called when the link in the external page is clicked.</p>
    </div>
    </body>
    </html>
    The above content specifically in the div will be pulled when the link is click in another page.

    Here is the page with the calling script:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Practice Template</title>
    <script src="jquery-1.5.1.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function() {
    $('.getContent').click(function () {
    $('#displayRemoteContent').load('content.html #test');
    return false;
    });
    });
    
    </script>
    </head>
    
    <body>
    <a href="#" class="getContent">Get Contents</a>
    <div id="displayRemoteContent"></div>
    </body>
    </html>
    Thanks everyone!


    IC

  2. #2
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again, I can't edit the post but wanted to add. What I am trying to do is have all the content on a single page in individual divs and call each div externally, rather than creating individual pages.

    IC


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •