0

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?

Community
  • 1
  • 1
somdow
  • 1
  • 1
  • 1
  • If the main page is fed by a content management system of some sort, why not simply make a new template for a mobile version of the same page? Seems rather silly to request the contents of a page that's dynamically generated, just to insert its contents into yet another dynamically generated page. – Marc B Apr 29 '11 at 17:29
  • 2
    Welcome to Stack Overflow. To get answers, you want to avoid comments like "it doesn't work" as they don't really give us anything to go on. You also definitely want to edit your question to include the pertinent code so it can be examined. – webbiedave Apr 29 '11 at 17:31

1 Answers1

3

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>
Lasar
  • 5,175
  • 4
  • 24
  • 22
  • This is definitely your best bet, somdow. @Lasar - I edited to add syntax highlighting to your code. Good answer! +1 – Ender Apr 29 '11 at 18:16
  • ok so, what i did was, i created 2 pages. 1. called pull4m.html and all it has this.
    hello world
    which is what i want to pull to main page. 2. the second page which is the one that as i understand it, is gonna PULL the "hello" div from page 1, has this then on the body tags,i put... this from the jquery .load() page which is this and thats as far as i got lol.
    – somdow Apr 29 '11 at 18:32
  • Does it even load the jquery file without http:// on it? You should also put the line into a block like `$(document).ready(function(){ put your code here });` If you could post the URL to your example or update your question with your current attempt, someone might be able to help. – Lasar Apr 29 '11 at 18:36
  • hello all, you guys are fast. sorry, the original did have the http. and here are the 2 links. http://somdowprod.net/4testing/pull http://somdowprod.net/4testing/pull4m thanks. – somdow Apr 29 '11 at 18:41
  • If I change your code to this, then it works for me: `$(document).ready(function(){ $('#result').load('pull4m.shtml #hello'); });` – Lasar Apr 29 '11 at 18:47
  • hey Lasar. ok so, this is what i have on the "pull.html" file which is part of what you put. now this doesnt work for me. i literally copy/pasted yours onto mine and nada. – somdow Apr 29 '11 at 19:10
  • edit*** i didnt see the edited post above. its now working. i dont know how but ITS WORKING lol. thanks to all. – somdow Apr 29 '11 at 19:14