I guess this is not possible without a big overhead of code.

E.g. Code:

        <div>
                I have a keyword inside
                <div>
                        I too have a keyword inside
                        <a href="#keyword_pos">and i have a keyword, too</a>
                        <a href="http://keywords.com";>and i am a link to a 
keyword site</a>
                </div>
        </div>

To find ALL "keyword" positions within ALL nested DOM-Nodes you would
need to find all nodes, build a tree object on your own and walk back
up from the every most depth children to its very top most parent
remembering if you replaced some text inside a childnode already so
you are not replacing it twice or more.

Even though you have to check every childnode of a parent to not
replace the content of hrefs, id's etc. but only the textnodes of each
child-dom-node.

I believe there is no easy way doing this.

Easiest approach - not real-world tested, just theory:

        var traversal = function( p, indent ){
                if( p.getChildren().length > 0 ){
                        p.getChildren().each( function(subElement){
                                traversal(subElement,indent+' ')
                        });
                } else {
                        // do whatever you need with this node
                        console.log( indent + '->' + p.get('tag') );
                }
        };
        traversal(document.body,'');


On 28 Mrz., 14:18, "Steve Onnis" <[email protected]> wrote:
> It would be better if i could somehow use something like a textNode or
> something as i need to locate the text string and find out what its parent
> element is
>
>
>
>
>
>
>
> -----Original Message-----
> From: Fli7e [mailto:[email protected]]
> Sent: Monday, 28 March 2011 11:02 PM
> To: MooTools Users
> Subject: [Moo] Re: replaceing a text string
>
> maybe this is what you are looking for ...
>
>         document.body.getElements('div').each( function(elm){
>                 elm.set(
>                         'html',
> elm.get('html').replace(/(searchterm)/g,"<span>$1</span>")
>                 );
>         });
>
> On 28 Mrz., 13:34, "Steve Onnis" <[email protected]> wrote:
> > can anyone suggest an easy way to replace some text on a page, well
> actually
> > i want to wrap text strings on a page with a span tag
>
> > so for example
>
> > <div>this is some text</div>
>
> > Would become
>
> > <div>this is <span>some</span> text</div>

Reply via email to