[jQuery] Re: What's the best way to replace text in a node?

2009-05-18 Thread George

That's what I was after - knew jQuery wouldn't disappoint!

Many thanks

George

On May 18, 1:08 pm, "Michael Price" 
wrote:
> You can use either:
>
> $("selector").text("New text");
> Or
> $("selector").html("New text");
>
> Both also work as getters if you don't provide an argument:
> theText = $("selector").text();
> theHTML = $("selector").html();
>
> Is this what you were after?
>
> Regards,
> Michael Price
>
> -Original Message-
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> Behalf Of George
> Sent: 18 May 2009 12:09
> To: jQuery (English)
> Subject: [jQuery] Re: What's the best way to replace text in a node?
>
> Sorry, folks, I'm not using remove(), I'm using empty() - like this:
>
> JQUERY
> text to be replaced
> $('#dText').empty().append('New text string')
>
> On May 18, 12:02 pm, George  wrote:
> > I'm guessing this should be a simple one for the jQuery stalwarts
> > here.  I've recently moved over from Protoype and was used to using
> > the update() function to replace text within a node - something like
> > this:
>
> > PROTOTYPE
> > text to be replaced
> > $('dText').update('New text string')
>
> > JQUERY
> > text to be replaced
> > $('#dText').remove().append('New text string')
>
> > Now it appears to me that in jQuery, there isn't an out of the box
> > function to replace the contents of a node without also replacing the
> > node too, hence the reason I am chaining remove() and append().  Is
> > there a better way to achieve this?
>
> > Many thanks
>
> > George


[jQuery] Re: What's the best way to replace text in a node?

2009-05-18 Thread Michael Price

You can use either:

$("selector").text("New text");
Or
$("selector").html("New text");

Both also work as getters if you don't provide an argument:
theText = $("selector").text();
theHTML = $("selector").html();

Is this what you were after?

Regards,
Michael Price

-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of George
Sent: 18 May 2009 12:09
To: jQuery (English)
Subject: [jQuery] Re: What's the best way to replace text in a node?


Sorry, folks, I'm not using remove(), I'm using empty() - like this:

JQUERY
text to be replaced
$('#dText').empty().append('New text string')



On May 18, 12:02 pm, George  wrote:
> I'm guessing this should be a simple one for the jQuery stalwarts
> here.  I've recently moved over from Protoype and was used to using
> the update() function to replace text within a node - something like
> this:
>
> PROTOTYPE
> text to be replaced
> $('dText').update('New text string')
>
> JQUERY
> text to be replaced
> $('#dText').remove().append('New text string')
>
> Now it appears to me that in jQuery, there isn't an out of the box
> function to replace the contents of a node without also replacing the
> node too, hence the reason I am chaining remove() and append().  Is
> there a better way to achieve this?
>
> Many thanks
>
> George




[jQuery] Re: What's the best way to replace text in a node?

2009-05-18 Thread donb

.text('some text') or .html('html') ?

On May 18, 7:08 am, George  wrote:
> Sorry, folks, I'm not using remove(), I'm using empty() - like this:
>
> JQUERY
> text to be replaced
> $('#dText').empty().append('New text string')
>
> On May 18, 12:02 pm, George  wrote:
>
> > I'm guessing this should be a simple one for the jQuery stalwarts
> > here.  I've recently moved over from Protoype and was used to using
> > the update() function to replace text within a node - something like
> > this:
>
> > PROTOTYPE
> > text to be replaced
> > $('dText').update('New text string')
>
> > JQUERY
> > text to be replaced
> > $('#dText').remove().append('New text string')
>
> > Now it appears to me that in jQuery, there isn't an out of the box
> > function to replace the contents of a node without also replacing the
> > node too, hence the reason I am chaining remove() and append().  Is
> > there a better way to achieve this?
>
> > Many thanks
>
> > George


[jQuery] Re: What's the best way to replace text in a node?

2009-05-18 Thread George

Sorry, folks, I'm not using remove(), I'm using empty() - like this:

JQUERY
text to be replaced
$('#dText').empty().append('New text string')



On May 18, 12:02 pm, George  wrote:
> I'm guessing this should be a simple one for the jQuery stalwarts
> here.  I've recently moved over from Protoype and was used to using
> the update() function to replace text within a node - something like
> this:
>
> PROTOTYPE
> text to be replaced
> $('dText').update('New text string')
>
> JQUERY
> text to be replaced
> $('#dText').remove().append('New text string')
>
> Now it appears to me that in jQuery, there isn't an out of the box
> function to replace the contents of a node without also replacing the
> node too, hence the reason I am chaining remove() and append().  Is
> there a better way to achieve this?
>
> Many thanks
>
> George