This didn't work for me...

$('#test').text().remove();

with this HTML:

<div id="test" style="width:200px; height:100px; border:1px solid black;">test 
test</div>

However, with this jQuery:

$('#test p:contains()').remove();

and this HTML:

<div id="test" style="width:200px; height:100px; border:1px solid 
black;"><p>test test</p></div>

I could remove any text from the p inside the div.  It did, however, remove the 
<p> element, as well,
but it did leave the div in place. (I put a border around the div so I could 
see if it remained...)

Seems like it should be easy to remove the text from within an element and 
leave the element, itself,
but I couldn't figure out a way in a few minutes of experimenting and reading 
the docs.

Rick



> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On 
> Behalf Of brian
> Sent: Saturday, January 24, 2009 12:19 PM
> To: jquery-en@googlegroups.com
> Subject: [jQuery] Re: remove()
> 
> 
> remove() should be used if you want to remove the div from the DOM. To
> empty its contents, just use text() or html(), which will replce the
> content of the div.
> 
> On Sat, Jan 24, 2009 at 12:05 PM, Charlie22 <ch...@post.cz> wrote:
> >
> > Thx, but I need leave DIV tag on the place..I thought $
> > ('#test>*').remove(), but no success.
> >
> > On 24 Led, 17:54, brian <bally.z...@gmail.com> wrote:
> >> $('#test').text('') or $('#test').html('') might be what you want.
> >>
> >>
> >>
> >> On Sat, Jan 24, 2009 at 11:22 AM, Charlie22 <ch...@post.cz> wrote:
> >>
> >> > I have question how easy remove content from DIV, e.g.
> >> > <div id='test'>test text</div>
> >>
> >> > I thought that code
> >> > $('#test').remove()
> >> > managed it, but it doesnt true. Thx in advance.- Skrýt citovaný text -
> >>
> >> - Zobrazit citovaný text -

Reply via email to