Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18732 > unrolled thread
| Started by | "Tony" <tony.johansson@inport.com> |
|---|---|
| First post | 2013-03-06 08:53 +0100 |
| Last post | 2013-03-06 12:43 -0500 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.javascript
I hope to shorten this working code that remove all myPolyLine element below mySVG element "Tony" <tony.johansson@inport.com> - 2013-03-06 08:53 +0100
Re: I hope to shorten this working code that remove all myPolyLine element below mySVG element "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-06 09:51 +0100
Re: I hope to shorten this working code that remove all myPolyLine element below mySVG element Jim T. <x@y.z> - 2013-03-06 12:43 -0500
| From | "Tony" <tony.johansson@inport.com> |
|---|---|
| Date | 2013-03-06 08:53 +0100 |
| Subject | I hope to shorten this working code that remove all myPolyLine element below mySVG element |
| Message-ID | <kh6siv$9i9$1@dont-email.me> |
function ClearSVGPolyLine()
{
var more = true;
while (more)
{
if (document.getElementById("myPolyLine") != null)
document.getElementById("mySVG").removeChild(document.getElementById("myPolyLine"));
else
more = false;
}
}
//Tony
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-03-06 09:51 +0100 |
| Message-ID | <XnsA17B6433BDB32eejj99@194.109.133.133> |
| In reply to | #18732 |
Tony wrote on 06 mrt 2013 in comp.lang.javascript:
> function ClearSVGPolyLine()
> {
> var more = true;
> while (more)
> {
> if (document.getElementById("myPolyLine") != null)
> document.getElementById("mySVG").removeChild(document.ge
> tElementById("myPolyLine"));
> else
> more = false;
> }
> }
If you hope to shorten something,
who are we to take that hope away by doing it for you?
===================
The "while" clause is not sensible,
as there must be at most one element id'ed "myPolyLine" in DOM-tree.
As such element either exists or not, testing for (theElement).
It does not have to be compared to null.
function ClearSVGPolyLine()
var temp = document.getElementById('myPolyLine');
if (temp)
temp.parentNode.removeChild(temp);
};
==================
However you could label the offending elements
with a name [or a class] and work on
the collection of elements in mySVG.
Don't dismiss parental guidance when removing a child.
Perhaps better make the function more general,
to be able to adress different canvasses andor
differently named collections of elements:
function ClearSvgElems(svg, elems)
var coll = document.getElementById(svg).getElementsByName(elems);
for (var c in coll)
coll[c].parentNode.removeChild(coll[c]);
};
ClearSvgElems('mySVG', 'myPolyLines');
ClearSvgElems('yourSVG', 'yourSquares');
[not tested]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Jim T. <x@y.z> |
|---|---|
| Date | 2013-03-06 12:43 -0500 |
| Message-ID | <jqvej8d4d4rcjnglikmf1b6e26mttj3pek@4ax.com> |
| In reply to | #18732 |
On Wed, 6 Mar 2013 08:53:24 +0100, "Tony" <tony.johansson@inport.com>
wrote:
>function ClearSVGPolyLine()
> {
> var more = true;
> while (more)
> {
> if (document.getElementById("myPolyLine") != null)
> document.getElementById("mySVG").removeChild(document.getElementById("myPolyLine"));
> else
> more = false;
> }
> }
>
>//Tony
I apologize if it's not the case, but your questions seem like
exercises from an introductory programming course. They aren't
difficult; you should make more of an effort to solve them on your
own.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web