Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22667
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <31598702.t5zLgSxMMz@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sat, 18 Jan 2014 12:53:47 +0100 |
| User-Agent | KNode/4.11.3 |
| Content-Transfer-Encoding | 8Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: Duplicating the last row of a Table |
| Newsgroups | comp.lang.javascript |
| References | <ZemAs3VzQa2SFwhs@invalid.uk.co.demon.merlyn.invalid> <bju1j4Fjf5sU1@mid.individual.net> |
| MIME-Version | 1.0 |
| Lines | 75 |
| NNTP-Posting-Date | 18 Jan 2014 12:54:06 CET |
| NNTP-Posting-Host | 79c8ca29.newsspool4.arcor-online.net |
| X-Trace | DXC=1^m:VVGc<iU\9P[:DUn00Q4IUK<Cl32<Q4Fo<]lROoRQ8kF<OcfhCO[@nETP0LS5IQDZm8W4\YJN\YUVHKH;GI^WjehMn`ohZVYY2n`TkS>^\U |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:22667 |
Show key headers only | View raw
Zlatko Duric wrote:
> That's a good behavior,
*What* is good behavior? Please do not top-post.
<http://PointedEars.de/faq#posting>
> because with the first quoted statement you're not getting a tbody
> element. You're getting its rows, and an array has no method appendChild
> (by default).
The object does not have an appendChild() method by default, indeed.
But that is _not_ due its being an Array; it is due to its _implementing
the HTMLCollection interface_.
<http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-64060425>
<http://www.w3.org/TR/2013/CR-html5-20130806/tabular-data.html#the-table-element>
> On 01/17/2014 10:44 PM, Dr J R Stockton wrote:
>
> > var Rose = document.getElementById("TB").rows
>
> [cut]
>
> > Rose.appendChild(newnode);
>
> [cut]
>
> > Cel = Rose.item(Y).cells.item(X)
Cel = Rose[Y].cells[X];
suffices. But this is not Pascal; variable identifiers that do not stand
for constructors or constant-like values should start lowercase.
> So, you can do something like this to get the tbody:
>
> var tb = document.getElementById('tb');
var tb = document.getElementById('TB');
Another possibility is to use table.tBodies[index].
> and then use that in further code and append a row to tb.
It was asked for *duplicating* the last row of a table, and that is easily
done:
var rows = table.rows;
var last_row = rows[rows.length - 1];
last_row.parentNode.appendChild(last_row.cloneNode(true));
or
last_row.parentNode.insertBefore(last_row.cloneNode(true), null);
I am using “last_row.parentNode” instead of “table” because the parent node
may be a “tbody” element node. [Cloning is vital because otherwise the
original row is moved to the end of the table or table section (you can use
that behavior to sort table rows quickly).]
> You get rows with something like document.getElementById('table-id').rows.
That accesses the NodeList of rows of the table, not of a table body,
though. Note that at least Chromium WebKit sorts the rows of the table in
*display* order; i.e., the rows for the table footer (“tfoot” element) come
last even though the corresponding “tr” elements do not. When in doubt,
access the rows of the table sections instead.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-17 21:44 +0000
Re: Duplicating the last row of a Table Zlatko Duric <zladuric@gmail.com> - 2014-01-18 01:52 +0100
Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-18 12:53 +0100
Re: Duplicating the last row of a Table RobG <rgqld@iinet.net.au> - 2014-01-19 17:00 +1000
Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-19 14:41 +0100
Re: Duplicating the last row of a Table "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-18 12:16 +0100
Re: Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-19 17:00 +0000
Re: Duplicating the last row of a Table Danny <dann90038@gmail.com> - 2014-01-18 11:32 -0800
csiph-web