In this case either html() or text() should work as there are no other
HTML elements inside the span.

As I said, in the "each" function "this" refer to the raw DOM node,
that does not have a "text()" function. The "text()" function is part
of jQuery, which acts as kind of a "wrapper" for the elements.

The text() function returns the text of the elements selected:

    http://docs.jquery.com/DOM/Attributes#text.28.29

To actually _set_ that text you need to use the text( 'string value' ) function:

    http://docs.jquery.com/DOM/Attributes#text.28_val_.29

See the definitions of html() and html( value ) on the same page.

You could use the "innerHTML" property of the span if you like, i.e.:

    this.innerHTML( this.innerHTML.replace(/index.cfm?a=wiki&tag=/gi, "") );

As for the site using jQuery already, do you mean the Whirlpool forum
or the wiki? The forum doesn't appear to include jQuery. I wasn't able
to check the wiki as the site went down for maintainence while I was
reading.

Karl Rudd

On 2/28/07, Yansky <[EMAIL PROTECTED]> wrote:
>
> Hi, thanks for the reply.
>
> I tried your code inside the function but it didn't work unfortunately.
>
> This is the actual site with the links I'm trying to convert:
> http://forums.whirlpool.net.au/forum-replies.cfm?t=661554
> I'm hoping to make a greasemonkey script since the site already uses the
> jQuery library.
>
> BTW, with my previous attempt, you said that the "each" function returns the
> raw DOM, but doesn't the "text" function access the text inside the node (in
> this case the span tag)?
>
> Thanks for your help so far, I've been trying to figure this out by myself
> all night. :)
>
>
> Karl Rudd wrote:
> >
> > You almost have it. The "each" function actually returns the "raw" DOM
> > element so to use jQuery you'll need to "enclose" this.
> >
> > Just replace the core with:
> >
> > var $this = $(this);
> > $this.html( $this.html().replace(/index.cfm?a=wiki&tag=/gi, "") );
> >
> > Karl Rudd
> >
> > On 2/28/07, Yansky <[EMAIL PROTECTED]> wrote:
> >>
> >> I have many of the following type of links on a page:
> >> < a
> >> href="htp://foo.com/index.cfm?a=wiki&tag=abc"><span>htp://foo.com/index.cfm?a=wiki&tag=abc</span>
> >>
> >> I'm trying to remove the text in between the span tags so that only the
> >> text
> >> after http://foo.com/index.cfm?a=wiki&tag= is showing. I have tried the
> >> following, but it doesn't seem to work.
> >>
> >> $('a > span').contains('index.cfm?a=wiki&tag=').each(function(i){
> >>   this.text().replace(/index.cfm?a=wiki&tag=/gi, "");
> >> });
> >>
> >> Can anyone point me in the right direction?
> >> Cheers.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Replace-text-in-array-tf3308186.html#a9201977
> >> Sent from the JQuery mailing list archive at Nabble.com.
> >>
> >>
> >> _______________________________________________
> >> jQuery mailing list
> >> [email protected]
> >> http://jquery.com/discuss/
> >>
> >
> > _______________________________________________
> > jQuery mailing list
> > [email protected]
> > http://jquery.com/discuss/
> >
> >
>
> --
> View this message in context: 
> http://www.nabble.com/Replace-text-in-array-tf3308186.html#a9202631
> Sent from the JQuery mailing list archive at Nabble.com.
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to