Hi,

thx a lot for your help.

@Colin

"doesn't work" means it returns NULL ;)
But of course, you are right.

I already feared that the "A string is not a document/DOM" is the main
problem.

@T.J. Crowder

thx! I'll try this soon, it looks promising :)

I already created a regEx solution but it's too unflexible for my
needs (handle "div","li',"span",...alt...title tags..maybe additional
style info and so on.... makes the regEx quite hard ..)






On 15 Jun., 13:41, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi,
>
> As Colin points out, you're trying to treat a String object like a
> Document (by calling getElementById), which isn't going to work.
>
> You have a couple of options.
>
> 1. Use string parsing to isolate the markup in that string for the
> element you want.  Once you have just that markup, you can use that
> with the #update call.  This could be fairly challenging to do in the
> general case (or maybe you have massive Regex fu), but perhaps in your
> specific case it might be simpler.
>
> 2. Alternately, use a document fragment[1][2].  This is to a large
> extent what document fragments are for -- holding copies of things and
> mucking about with them off-to-the-side.  I was surprised not to have
> an example lying around and wanted to refresh my memory, so here's a
> small example:
>
> http://pastie.org/512428
>
> (Supply your own 'fragment2.html'; it can be any valid HTML doc, make
> sure it has an element with the ID 'two' in it -- or change the ID
> used in the example.)
>
> Basically, I request the page via Ajax.Request, then create a fragment
> to hold the result and (because I'm lazy) a div inside that fragment
> so that I can use Prototype's Element#update function.  I put the
> retrieved document inside the div (almost certainly creating a
> completely invalid document temporarily!), then go find the element
> inside that with the ID I want, and update a target div with that
> element.
>
> Note this line:
>
>     elm = findElementByID(div, 'two');
>
> I coded up a quick recursive-descent lookup function for finding the
> element by ID because you can't use document.getElementById (or
> Prototype's $) to find it in the fragment -- the fragment isn't in the
> document (which is probably a good thing, otherwise you'd be massively
> worried about ID conflicts loading up an entire page like this).
> Interestingly, if you're using Prototype 1.6.1 RC2, you could (as of
> the time of this writing) use:
>
>     elm = div.select('#two');
>
> ...instead, because apparently Prototype's new Sizzle-based selector
> engine finds the element correctly, wheras in 1.6.0.3 the old selector
> engine doesn't.  But I wouldn't.  Firstly, the simple recursive-
> descent function is small and doesn't take long; secondly, I wouldn't
> bet on future changes not causing Element#select to stop working in
> this context -- barring finding documentation saying that it will, of
> course.  I don't know Sizzle well enough to know if it intentionally
> handles this situation.
>
> [1]https://developer.mozilla.org/en/dom/documentfragment
> [2]http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-B63ED1A3
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Jun 13, 10:04 pm, fufolewe <rentsch.dan...@gmail.com> wrote:
>
> > Hi,
>
> > I have a simple problem which is driving me nuts:
>
> > I would like to make an AJAX req which returns the whole page - select
> > an element by its ID from the response text and update "targetDiv"
> > with this element (myDivID).
>
> > But it doenst work :/
>
> > function loadContent(url) {
>
> >         new Ajax.Request(url, {
> >                         method: 'get',
> >                         onSuccess: function(transport) {
>
> >                         var response = transport.responseText;
>
> >                         var element = response.getElementById( 'myDivID');
>
> >                         $('targetDiv').update(element);
>
> >                         }
> >         });
>
> > }
>
> > Some ideas?
>
> > thx
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to