Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20352 > unrolled thread

How to clear/remove all the objects in a DIV?

Started byjustaguy <lichunshen84@gmail.com>
First post2013-06-19 11:14 -0700
Last post2013-06-20 07:05 -0700
Articles 20 on this page of 21 — 12 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to clear/remove all the objects in a DIV? justaguy <lichunshen84@gmail.com> - 2013-06-19 11:14 -0700
    Re: How to clear/remove all the objects in a DIV? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-19 20:36 +0200
      Re: How to clear/remove all the objects in a DIV? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-06-20 19:52 +0100
        Perfect Parlance (was: How to clear/remove all the objects in a DIV?) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-06-21 01:25 +0200
          Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-21 09:41 +0200
            Re: Perfect Parlance Christoph Michael Becker <cmbecker69@arcor.de> - 2013-06-28 23:56 +0200
              Re: Perfect Parlance "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-29 00:19 +0200
              Re: Perfect Parlance "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-06-29 01:20 +0300
          Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?) Gene Wirchenko <genew@telus.net> - 2013-06-21 12:52 -0700
            Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?) John Harris <niam@jghnorth.org.uk.invalid> - 2013-06-24 21:03 +0100
              Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-25 10:50 +0200
    Re: How to clear/remove all the objects in a DIV? justaguy <lichunshen84@gmail.com> - 2013-06-19 13:57 -0700
      Re: How to clear/remove all the objects in a DIV? JJ <duh@nah.meh> - 2013-06-20 05:20 +0700
      Re: How to clear/remove all the objects in a DIV? Gregor Kofler <usenet@gregorkofler.com> - 2013-06-20 00:57 +0200
        Re: How to clear/remove all the objects in a DIV? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-20 01:16 +0200
        Re: How to clear/remove all the objects in a DIV? justaguy <lichunshen84@gmail.com> - 2013-06-19 17:21 -0700
          Re: How to clear/remove all the objects in a DIV? justaguy <lichunshen84@gmail.com> - 2013-06-19 17:39 -0700
            Re: How to clear/remove all the objects in a DIV? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-20 15:27 +0000
              Re: How to clear/remove all the objects in a DIV? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-20 18:15 +0200
                Re: How to clear/remove all the objects in a DIV? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-06-20 21:01 -0300
    Re: How to clear/remove all the objects in a DIV? justaguy <lichunshen84@gmail.com> - 2013-06-20 07:05 -0700

Page 1 of 2  [1] 2  Next page →


#20352 — How to clear/remove all the objects in a DIV?

Fromjustaguy <lichunshen84@gmail.com>
Date2013-06-19 11:14 -0700
SubjectHow to clear/remove all the objects in a DIV?
Message-ID<9f3e516a-a7fb-447a-8d3d-7f1a2c40b57b@googlegroups.com>
Hi,

I have this DIV below,

<DIV id="workspace"> ... lots of dynamically generated objects here... </DIV>

Now, i want this div to be empty, and attempted with document.getElementById('workspace').textContent = '' with no effects.

What's the correct syntax?

Thanks.

[toc] | [next] | [standalone]


#20354

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-19 20:36 +0200
Message-ID<4145994.AlPci6QIaN@PointedEars.de>
In reply to#20352
justaguy wrote:

> I have this DIV below,
> 
> <DIV id="workspace"> ... lots of dynamically generated objects here...
> </DIV>
> 
> Now, i want this div to be empty, and attempted with
       ^
> document.getElementById('workspace').textContent = '' with no effects.
> 
> What's the correct syntax?

This syntax is essentially correct (again you should have posted the 
*relevant* parts of the *real* code in a *separate* paragraph); the whole 
markup or browser (DOM implementation) may not.  “With no effects” is most 
certainly a wrong description, see <http://devtoolsecrets.com/>.

The personal pronoun for oneself is *always* spelled with a capital letter 
in English.

Get a real name.  Do not use Google Groups for posting if you cannot work 
around its bugs (e.g., producing lines of astronomical length).

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20375

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-06-20 19:52 +0100
Message-ID<AmxGSmO290wRFwd2@invalid.uk.co.demon.merlyn.invalid>
In reply to#20354
In comp.lang.javascript message <4145994.AlPci6QIaN@PointedEars.de>,
Wed, 19 Jun 2013 20:36:34, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

>The personal pronoun for oneself is *always* spelled with a capital letter
>in English.

That is certainly false, as is shown by what you quote, and by the fact
that in English speech it is never spelt at all.  Think before you
write, and continue doing so until you achieve correctness and
exactitude.  And, of course, read e e cummings, and "archy and
mehitabel".

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
   Web  <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

[toc] | [prev] | [next] | [standalone]


#20377 — Perfect Parlance (was: How to clear/remove all the objects in a DIV?)

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2013-06-21 01:25 +0200
SubjectPerfect Parlance (was: How to clear/remove all the objects in a DIV?)
Message-ID<51c38f5b$0$6634$9b4e6d93@newsspool2.arcor-online.net>
In reply to#20375
Dr J R Stockton wrote:
> Think before you write, and continue doing so until you achieve
> correctness and exactitude.

Good advice.  But if we all adhere to this, nobody would post in this
(or any other) newsgroup, methinks.

> [...] by the fact that in English speech it is never spelt at all.

AFAIK nothing is ever *spelled* in any *spoken* language at all.  But
then, Usenet is not about *speaking*, but about *writing*.

BTW: Have you even considered changing the subject of your post, as it
is not related to the topic at all?

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#20380 — Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-06-21 09:41 +0200
SubjectRe: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)
Message-ID<XnsA1E6629ED939Deejj99@194.109.133.133>
In reply to#20377
Christoph Michael Becker wrote on 21 jun 2013 in comp.lang.javascript:

> Dr J R Stockton wrote:

>> [...] by the fact that in English speech it is never spelt at all.
> 
> AFAIK nothing is ever *spelled* in any *spoken* language at all.

Your "AFAIK" and "any" are mutual exclusive.

Perhaps you are under the delusion of a permanent monoglottic or 
parvoglottic spell?

> But then, Usenet is not about *speaking*, but about *writing*.

If you "say" so.

=========== btw =================

Spelled vs. spelt

In American English, spelt primarily refers to the hardy wheat grown 
mostly in Europe, and the verb spell makes spelled in the past tense and 
as a past participle. In all other main varieties of English, spelt and 
spelled both work as the past tense and past participle of spell, at least 
where spell means to form words letter by letter or (with out) to make 
clear. Outside the U.S., the two forms are interchangeable in these uses, 
and both are common.

But when spell carries the sense to temporarily relieve (someone) from 
work, spelled is the preferred form throughout the English-speaking world. 
This is a minor point, though, as this sense of spell is rarely used 
outside the U.S., where it is most common.

Spelled is not a recent Americanism, as many people assume (including some 
who have commented on this post). Both spelled and spelt are old, and 
examples of each are easily found in historical Google Books searches 
covering the 17th and 18th centuries. It is true, however, that spelt was 
ascendant everywhere through most of the 19th century. This ended when 
Americans permanently settled on spelled around 1900.

<http://grammarist.com/spelling/spelled-spelt/>

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20488 — Re: Perfect Parlance

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2013-06-28 23:56 +0200
SubjectRe: Perfect Parlance
Message-ID<51ce064f$0$6573$9b4e6d93@newsspool3.arcor-online.net>
In reply to#20380
Evertjan. wrote:
> Christoph Michael Becker wrote on 21 jun 2013 in comp.lang.javascript:
> 
>> Dr J R Stockton wrote:
> 
>>> [...] by the fact that in English speech it is never spelt at all.
>>
>> AFAIK nothing is ever *spelled* in any *spoken* language at all.
> 
> Your "AFAIK" and "any" are mutual exclusive.

IBTD.

> Perhaps you are under the delusion of a permanent monoglottic or 
> parvoglottic spell?

I hope that I am not under any spell.  BTW: what's the meaning of
"parvoglottic"?  Looking it up with Google just brings me back here. :)

>> But then, Usenet is not about *speaking*, but about *writing*.
> 
> If you "say" so.

Well "said". :)

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#20489 — Re: Perfect Parlance

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-06-29 00:19 +0200
SubjectRe: Perfect Parlance
Message-ID<XnsA1EE33F78C03eejj99@194.109.133.133>
In reply to#20488
Christoph Michael Becker wrote on 28 jun 2013 in comp.lang.javascript:

>> Perhaps you are under the delusion of a permanent monoglottic or 
>> parvoglottic spell?
> 
> I hope that I am not under any spell.  BTW: what's the meaning of
> "parvoglottic"? 

Not understanding this word is a typical example of the same.

Lat. parvus. -a, -um = small, little, cheap

glot you should understand, if you understood monoglottic.

>  Looking it up with Google just brings me back here. :)

Ah, quelle perfection de recursion!

<http://aiellodba.blogspot.nl/2011/09/la-recursion-es-divina.html>

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20490 — Re: Perfect Parlance

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2013-06-29 01:20 +0300
SubjectRe: Perfect Parlance
Message-ID<kql1t4$fp0$1@dont-email.me>
In reply to#20488
2013-06-29 0:56, Christoph Michael Becker wrote:

> IBTD.

Consider the opportunity of looking much less foolish by posting 
sensible on-topic messages instead of ETLAs that were not funny ever.

Then again, due to constant trolling and other disruptions, this group 
seems to be close to being virtually dead. Are you sure you want to be 
part of making this final this way?

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#20381 — Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)

FromGene Wirchenko <genew@telus.net>
Date2013-06-21 12:52 -0700
SubjectRe: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)
Message-ID<8mb9s8tiorm132oc3ujfj4as98ep0gbr0c@4ax.com>
In reply to#20377
On Fri, 21 Jun 2013 01:25:11 +0200, Christoph Michael Becker
<cmbecker69@arcor.de> wrote:

>Dr J R Stockton wrote:
>> Think before you write, and continue doing so until you achieve
>> correctness and exactitude.
>
>Good advice.  But if we all adhere to this, nobody would post in this
>(or any other) newsgroup, methinks.
>
>> [...] by the fact that in English speech it is never spelt at all.
>
>AFAIK nothing is ever *spelled* in any *spoken* language at all.  But
>then, Usenet is not about *speaking*, but about *writing*.

     What is a spelling bee then?

>BTW: Have you even considered changing the subject of your post, as it
>is not related to the topic at all?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#20419 — Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2013-06-24 21:03 +0100
SubjectRe: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)
Message-ID<pd9hs8ls4s5qcdns56g68ibj0fa7ipei3p@4ax.com>
In reply to#20381
On Fri, 21 Jun 2013 12:52:00 -0700, Gene Wirchenko <genew@telus.net>
wrote:

  <snip>
>     What is a spelling bee then?
  <snip>

It's people speaking about writing of course :-)

  John

[toc] | [prev] | [next] | [standalone]


#20430 — Re: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-06-25 10:50 +0200
SubjectRe: Perfect Parlance (was: How to clear/remove all the objects in a DIV?)
Message-ID<XnsA1EA6E43ED5EEeejj99@194.109.133.133>
In reply to#20419
John Harris wrote on 24 jun 2013 in comp.lang.javascript:

> On Fri, 21 Jun 2013 12:52:00 -0700, Gene Wirchenko <genew@telus.net>
> wrote:
> 
>   <snip>
>>     What is a spelling bee then?
>   <snip>
> 
> It's people speaking about writing of course :-)

Thought it was about a godspell of bees spilling honey.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20355

Fromjustaguy <lichunshen84@gmail.com>
Date2013-06-19 13:57 -0700
Message-ID<9e65bc40-ab97-40aa-91ca-5790829262b3@googlegroups.com>
In reply to#20352
On Wednesday, June 19, 2013 2:14:09 PM UTC-4, justaguy wrote:
> Hi,
> 
> 
> 
> I have this DIV below,
> 
> 
> 
> <DIV id="workspace"> ... lots of dynamically generated objects here... </DIV>
> 
> 
> 
> Now, i want this div to be empty, and attempted with document.getElementById('workspace').textContent = '' with no effects.
> 
> 
> 
> What's the correct syntax?
> 
> 
> 
> Thanks.

I now have a better syntax,
var node = document.getElementById('workspace'); 
while (node.hasChildNodes()) {node.removeChild();};

But still, it does not remove all the newly inserted objects inside the 'workspace' DIV, how come?

Thanks.

[toc] | [prev] | [next] | [standalone]


#20356

FromJJ <duh@nah.meh>
Date2013-06-20 05:20 +0700
Message-ID<hpcreaqu65t6.wmcpcaz0xdqg.dlg@40tude.net>
In reply to#20355
On Wed, 19 Jun 2013 13:57:26 -0700 (PDT), justaguy wrote:
> I now have a better syntax,
> var node = document.getElementById('workspace'); 
> while (node.hasChildNodes()) {node.removeChild();};
> 
> But still, it does not remove all the newly inserted objects inside the 'workspace' DIV, how come?

Do you even know what that code does exactly?

[toc] | [prev] | [next] | [standalone]


#20357

FromGregor Kofler <usenet@gregorkofler.com>
Date2013-06-20 00:57 +0200
Message-ID<kptcno$vnu$1@dont-email.me>
In reply to#20355
Am 19.06.2013 22:57, justaguy meinte:
> On Wednesday, June 19, 2013 2:14:09 PM UTC-4, justaguy wrote:
>> Hi,
>>
>>
>>
>> I have this DIV below,
>>
>>
>>
>> <DIV id="workspace"> ... lots of dynamically generated objects here... </DIV>
>>
>>
>>
>> Now, i want this div to be empty, and attempted with document.getElementById('workspace').textContent = '' with no effects.
>>
>>
>>
>> What's the correct syntax?
>>
>>
>>
>> Thanks.
>
> I now have a better syntax,
> var node = document.getElementById('workspace');
> while (node.hasChildNodes()) {node.removeChild();};
>
> But still, it does not remove all the newly inserted objects inside the 'workspace' DIV, how come?

Maybe because element.removeChild() requires the node to be removed as 
an argument?

Gregor

[toc] | [prev] | [next] | [standalone]


#20359

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-20 01:16 +0200
Message-ID<1647425.nE8tuRFhyd@PointedEars.de>
In reply to#20357
Gregor Kofler wrote:

> Am 19.06.2013 22:57, justaguy meinte:
>> I now have a better syntax,
>> var node = document.getElementById('workspace');
>> while (node.hasChildNodes()) {node.removeChild();};
>>
>> But still, it does not remove all the newly inserted objects inside the
>> 'workspace' DIV, how come?
> 
> Maybe because element.removeChild() requires the node to be removed as
> an argument?

And therefore throws “Error: NotFoundError: DOM Exception 8” and the like to 
the script console…

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20360

Fromjustaguy <lichunshen84@gmail.com>
Date2013-06-19 17:21 -0700
Message-ID<3aa0c769-a0d9-4af6-bd01-af62a3c8c47e@googlegroups.com>
In reply to#20357
On Wednesday, June 19, 2013 6:57:44 PM UTC-4, Gregor Kofler wrote:
> Am 19.06.2013 22:57, justaguy meinte:
> 
> > On Wednesday, June 19, 2013 2:14:09 PM UTC-4, justaguy wrote:
> 
> >> Hi,
> 
> >>
> 
> >>
> 
> >>
> 
> >> I have this DIV below,
> 
> >>
> 
> >>
> 
> >>
> 
> >> <DIV id="workspace"> ... lots of dynamically generated objects here... </DIV>
> 
> >>
> 
> >>
> 
> >>
> 
> >> Now, i want this div to be empty, and attempted with document.getElementById('workspace').textContent = '' with no effects.
> 
> >>
> 
> >>
> 
> >>
> 
> >> What's the correct syntax?
> 
> >>
> 
> >>
> 
> >>
> 
> >> Thanks.
> 
> >
> 
> > I now have a better syntax,
> 
> > var node = document.getElementById('workspace');
> 
> > while (node.hasChildNodes()) {node.removeChild();};
> 
> >
> 
> > But still, it does not remove all the newly inserted objects inside the 'workspace' DIV, how come?
> 
> 
> 
> Maybe because element.removeChild() requires the node to be removed as 
> 
> an argument?
> 

I saw two samples of supposedly removing all the objects within an element.

a)
var node = document.getElementById('workspace');
while (node.hasChildNodes()) {
    node.removeChild(node.lastChild);
}

b)
var node = document.getElementById('workspace');
while (node.hasChildNodes()) {
    node.removeChild(node.firstChild);
}

I tried b), all the objects are still inside the 'workspace' DIV.
And I don't why it's called 'firstChild', thought it should be every 'child' within... so, did something for the heck of it of 
while (node.hasChildNodes()) {
    node.removeChild()
}

Weird tho, with Firefox 21 for Windows, no error returned.


[toc] | [prev] | [next] | [standalone]


#20361

Fromjustaguy <lichunshen84@gmail.com>
Date2013-06-19 17:39 -0700
Message-ID<18a09a93-fbbf-4d61-a59b-310a06d4d03d@googlegroups.com>
In reply to#20360
On Wednesday, June 19, 2013 8:21:17 PM UTC-4, justaguy wrote:
> On Wednesday, June 19, 2013 6:57:44 PM UTC-4, Gregor Kofler wrote:
> 
> > Am 19.06.2013 22:57, justaguy meinte:
> 
> > 
> 
> > > On Wednesday, June 19, 2013 2:14:09 PM UTC-4, justaguy wrote:
> 
> > 
> 
> > >> Hi,
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> I have this DIV below,
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> <DIV id="workspace"> ... lots of dynamically generated objects here... </DIV>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> Now, i want this div to be empty, and attempted with document.getElementById('workspace').textContent = '' with no effects.
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> What's the correct syntax?
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> Thanks.
> 
> > 
> 
> > >
> 
> > 
> 
> > > I now have a better syntax,
> 
> > 
> 
> > > var node = document.getElementById('workspace');
> 
> > 
> 
> > > while (node.hasChildNodes()) {node.removeChild();};
> 
> > 
> 
> > >
> 
> > 
> 
> > > But still, it does not remove all the newly inserted objects inside the 'workspace' DIV, how come?
> 
> > 
> 
> > 
> 
> > 
> 
> > Maybe because element.removeChild() requires the node to be removed as 
> 
> > 
> 
> > an argument?
> 
> > 
> 
> 
> 
> I saw two samples of supposedly removing all the objects within an element.
> 
> 
> 
> a)
> 
> var node = document.getElementById('workspace');
> 
> while (node.hasChildNodes()) {
> 
>     node.removeChild(node.lastChild);
> 
> }
> 
> 
> 
> b)
> 
> var node = document.getElementById('workspace');
> 
> while (node.hasChildNodes()) {
> 
>     node.removeChild(node.firstChild);
> 
> }
> 
> 
> 
> I tried b), all the objects are still inside the 'workspace' DIV.
> 
> And I don't why it's called 'firstChild', thought it should be every 'child' within... so, did something for the heck of it of 
> 
> while (node.hasChildNodes()) {
> 
>     node.removeChild()
> 
> }
> 
> 
> 
> Weird tho, with Firefox 21 for Windows, no error returned.

I just took another look, there appeared to be a typo of the id of 'workspace', very weird, I usually copied and pasted it...
Anyway, corrected the typo, 
node.removeChild(node.lastChild) etc. works.

HOWEVER, I now have a new requirement, that is, I wonder how we could remove every object between two IDs within a DIV, and let me continue to use this DIV of id 'workspace'.

It looks like this:
<DIV id="workspace">
<table>
<tr><td>abc</td> <td>...</td> </tr>
...
<tr id="start"><td>abc</td> <td>...</td> </tr>
...
<tr id="stop"><td>abc</td> <td>...</td> </tr>
...
<tr><td>abc</td> <td>...</td> </tr>
</table>
</DIV>

And there are a bunch of objects dynamically inserted into this DIV and between 
the ID of 'start' and 'stop',
the new question is, how do we remove every object between
'start' and 'stop'?
Is there something like removeBefore(nodeName or ID) or deleteBefore (nodeName or ID) or removeAfter or deleteAfter?

Many thanks.

[toc] | [prev] | [next] | [standalone]


#20367

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-06-20 15:27 +0000
Message-ID<kpv70g$c33$3@dont-email.me>
In reply to#20361
On Wed, 19 Jun 2013 17:39:37 -0700, justaguy wrote:

> Is there something like removeBefore(nodeName or ID) or deleteBefore
> (nodeName or ID) or removeAfter or deleteAfter?

Is it possible that when you delete the immediate children, their 
descendants are still present?

Your div is the root of a tree. What you need to do is trim the tree back 
to the root starting at the most distant branch.

Possibly something like this:

function remove_children_and_node( node ) {
	while ( node.hasChildNodes() )
		remove_children_and_node( node.firstChild );
	node.parentNode.removeChild( node );
}

x = document.getElementById("myDiv");
while ( x.hasChildNodes() )
	remove_children_and_node( x.firstChild );

Not tested, obviously.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#20368

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-20 18:15 +0200
Message-ID<9875396.0bNLEoWOxd@PointedEars.de>
In reply to#20367
Denis McMahon wrote:

> On Wed, 19 Jun 2013 17:39:37 -0700, justaguy wrote:
>> Is there something like removeBefore(nodeName or ID) or deleteBefore
>> (nodeName or ID) or removeAfter or deleteAfter?
> 
> Is it possible that when you delete the immediate children, their
> descendants are still present?

No.  Deleting a node deletes all of its descendants.  However, care must be 
taken regarding the event listeners on descendents as some implementations 
do not clean up properly.
 
> Your div is the root of a tree. What you need to do is trim the tree back
> to the root starting at the most distant branch.

No, you do not.  You just use the “previousSibling” property repeatedly.
 
> […]
> Not tested, obviously.

Like your other junk postings.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20378

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2013-06-20 21:01 -0300
Message-ID<kq0558$40i$1@speranza.aioe.org>
In reply to#20368
On 20/06/2013 13:15, Thomas 'PointedEars' Lahn wrote:
> Denis McMahon wrote:
>> Your div is the root of a tree. What you need to do is trim the tree back
>> to the root starting at the most distant branch.
>
> No, you do not.  You just use the “previousSibling” property repeatedly.
>
>> […]
>> Not tested, obviously.
>
> Like your other junk postings.
>

Stalker troll.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web