On 9/19/07, Jeffrey Herr <[EMAIL PROTECTED]> wrote:
>
>
> Narrative:
> I'm trying to scrape a Wiki page within my company, extract the header
> text only, then include that into the home page on our Intranet.
> I thought: easy!  I load the Wiki page into separate DOM starting at
> the Div containing the actual content, find all the 'h3' elements, and
> for each one, extract the text and append to a Div on my home page.
> Sounds simple, but for the life of me, I can't get things to work
> right...
> 1) the find() isn't working.  When it's in, it finds nothing.
> 2) the empty() isn't working; the 'span'  is what's handed to me when
> I remove the 'find()' filter.
>
> Any ideas how to do what I'm trying to accomplish?  Less importantly,
> what am I misunderstanding about the code shown below?
>
> Thanks for the help-
>
> Jeff
>
> - - - - - - - - - - - - - -
>
> <head>
> {snip}
>         $(document).ready(function(){
>                         $("#loadpage").empty() ;
>                         var myDOM = new jQuery("<span/>") ;
>                         myDOM.empty() ;
>
>                         var mydata = myDOM.load("/jamwiki/en/TechTesting
> #content-
> article") ;
>                         mydata.find("h3").each(function(i) {
>                                 alert("Got one!" ) ;
>                                 $("#loadpage").append($(this)) ;
>                                 return true ;
>                         } ) ;


Here's what's happening. You call myDOM.load(...) and it runs out to fetch
your content. While it's gone doing that, the next statement executes
immediately. That's why it's not find()-ing any h3s. The content isn't back
yet. load() accepts as a third parameter a callback function. The function
you pass will get called when the content returns and has been loaded in
your element. Use this guy to do your find(), each(), and append(). Or more
simply, (untested):

myDom.load(url,, function() {
  $("h3", this).appendTo("#loadpage");
});

Another thing - you're setting mydata = myDOM.load() as if load() is
returning the data. It's returning the same jQuery object that myDOM is. It
works as currently written, but it looks like something else, so that could
cause problems if code changes.

- Richard

Reply via email to