Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #13900
| Path | csiph.com!usenet.pasdenom.info!news.chainon-marquant.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <1402505.AFRqVoOGUt@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sun, 13 May 2012 15:50:16 +0200 |
| User-Agent | KNode/4.4.11 |
| 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: Modify Element Tag Question |
| Newsgroups | comp.lang.javascript |
| References | <a158cjFt46U1@mid.individual.net> <4faf23ae$0$2892$a8266bb1@newsreader.readnews.com> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 134 |
| NNTP-Posting-Date | 13 May 2012 15:50:18 CEST |
| NNTP-Posting-Host | 919864d9.newsspool2.arcor-online.net |
| X-Trace | DXC=11lfa7f3H2R\PS5Xo=M[RVA9EHlD;3YcR4Fo<]lROoRQ8kF<OcfhCO[IAON^PBnRUWDZm8W4\YJN\J`:FmdeL>KPfQ>EOE\[m`[Bl89g_ekZaU |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:13900 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
Denis McMahon wrote:
> On Fri, 11 May 2012 13:42:09 -0600, Mel Smith wrote:
>> In my phone book (of 613 multi-line entries in a table)
>>, I am
>> currently
>> 'bolding' the names of the people, and leaving other fields 'unbolded'.
>>
>> Now, when a user decides to change the sorting order to street
>> address,
>> I wish to 'unbold' the names, and bold the street addresses.
>
> Hmm
If only you would stop right there, posterity would be saved a lot of
precious bandwidth that they are going to need desperately.
> The way I think I would do it, assuming that each row has a series of td
> elements ....
>
> To the td elements that contain names, I would add 'class="name"', and to
> the td elements that hold addresses, I would add 'class="addr"'
So much, so good.
> Then, as an appendage to the sort routines, call something like boldCells
> as shown below with either "name" or "addr" (it can be expanded to other
> fields if needed):
How do you manage coming up so easily with the worst "solutions" possible?
Did V'Often Wrong'K teach you?
> function boldCells( embolden ) {
> var cells = document.getElementsByTagName( "td" );
That inefficient, error-prone method call is unnecessary. HTMLTableElement
objects have a `rows' property, and HTMLTableRowElement objects have a
`cells' property, that hold a reference to a NodeList of references to
HTMLTableRowElement objects and HTMLTableCellElement objects, respectively.
> var ix = cells.length;
> var cell, class;
`class' is a future reserved word; it cannot be the name of a variable as
that must be an *identifier* (see the ECMAScript Language Specification, 5.1
Edition, section 7.5.3, but also about any JS tutorial out there, for any
common meaning of "JS" being a programming language).
As result, this code does not compile, and does not run. For example, in
Chromium 18.x:
| > var class = 42;
| SyntaxError: Unexpected reserved word
> while ( ix-- ) {
> cell = cells.item( ix );
This rather expensive and potentially incompatible call of the `item' method
of the `cells' NodeList object is not necessary, you can simply write
cells[ix]
instead.
<http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>
> class = cell.attributes.getNamedItem( "class" );
OMG. As regulars will know, an HTMLElement object has a `className'
property. A simple
cell.className
does it all, and is a lot more compatible than your bloatcode (even the
equally bloated and equally wrong cell.getAttribute("class") is more
efficient than that).
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037>
> if ( class.indexOf( "name" ) != -1 ) {
This is insufficient to determine if the attribute value contains a certain
class name, because it will result in false positives if a class name is,
for example, "foonamebar". (Besides, the index of a substring can never be
negative, so you should lose the loose comparison and use `> -1' instead.)
We have already discussed here ad nauseam how to determine efficiently and
reliably if a CSS class name is in a `class' attribute value. For those who
have not been paying attention, or are new here, the consensus reached in
those discussions was:
if (/(^|\s)name(\s|$)/.test(cell.className))
{
…
}
[`\b' as delimiter does not suffice, because (CSS) class names may contain
non-ASCII characters, which are considered non-word characters. `\s' should
suffice but does not match HTML's white-space definition exactly in all
implementations; so a custom character class might be used instead.]
<http://www.w3.org/TR/1999/REC-html401-19991224/struct/
global.html#adef-class>
> if ( embolden == "name" )
> cell.style.fontWeight = "bold";
> else
> cell.style.fontWeight = "normal";
> }
> else if ( class.indexOf( "addr" ) != -1 ) {
> if ( embolden == "addr" )
> cell.style.fontWeight = "bold";
> else
> cell.style.fontWeight = "normal";
> }
Or you could simply switch the class name.
foo.className = "bold";
> }
>
> Note - code is untested!
… and written cluelessly, like everything else coming from you before.
Not just in this newsgroup.
PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-11 13:42 -0600
Re: Modify Element Tag Question Martin Honnen <mahotrash@yahoo.de> - 2012-05-12 12:00 +0200
Re: Modify Element Tag Question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-12 15:02 +0200
Re: Modify Element Tag Question John G Harris <john@nospam.demon.co.uk> - 2012-05-12 16:15 +0100
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-12 14:32 -0600
Re: Modify Element Tag Question Dr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid> - 2012-05-12 19:29 +0100
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-12 18:08 -0600
Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-13 08:11 +0000
Re: Modify Element Tag Question Martin Honnen <mahotrash@yahoo.de> - 2012-05-13 11:25 +0200
Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-14 20:19 +0100
Re: Modify Element Tag Question Denis McMahon <denismfmcmahon@gmail.com> - 2012-05-13 02:59 +0000
Re: Modify Element Tag Question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-13 15:50 +0200
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-13 08:56 -0600
Re: Modify Element Tag Question Dr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid> - 2012-05-14 20:01 +0100
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-13 09:00 -0600
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-14 08:45 -0600
Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-14 16:31 -0700
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-15 09:03 -0600
Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-15 20:04 +0100
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-15 22:19 -0600
Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-17 19:13 +0100
Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-17 18:48 -0700
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-18 13:14 -0600
Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-19 20:47 +0100
Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-20 08:31 +0000
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-20 18:25 -0600
Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-21 16:06 +0000
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-21 13:24 -0600
Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-21 13:34 -0600
Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-21 13:09 -0700
Re: Modify Element Tag Question Dr J R Stockton <reply1221@merlyn.demon.co.uk.not.invalid> - 2012-05-21 20:33 +0100
csiph-web