Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <2943028.PjCfEcWMYn@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 12 May 2012 15:02:40 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <4fae34c6$0$9503$9b4e6d93@newsspool1.arcor-online.net> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 87 NNTP-Posting-Date: 12 May 2012 15:02:42 CEST NNTP-Posting-Host: 385ceac3.newsspool1.arcor-online.net X-Trace: DXC=KPU@3`]Ai;BfR=K_:[S?JcZ] X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:13883 Martin Honnen wrote: > 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. >> >> So, is there a 'placeholder' HTML Element Tag that I can use for all >> sortable fields (and later search for) so that the text is displayed >> correctly but *unbolded*. > > Define a class with CSS e.g. > td.sorted { font-weight: bold; } > then make sure you manipulate the className for the cells you want to > change e.g. > function changeSortStyle(table, unsortedIndex, sortedIndex) { > for (var i = 0, l = table.rows.length; i < l; i++) { > table.rows[i].cells[unsortedIndex].className = ''; > table.rows[i].cells[sortedIndex].className = 'sorted'; > } > } However, it is a lot more efficient to give each column (or element, in general) a class corresponding to its content in advance, and just change the corresponding style rule. Finding that rule only has to be done once and is most beautifully done in conforming implementations of ECMAScript, 5.1 Edition (or emulations thereof): /* See also */ var findRules = (function () { var _slice = Array.prototype.slice; var a = []; var _concat = Array.prototype.concat; function toArray (obj) { return _slice.call(obj || a); } return function (selector, exactMatch) { var prefix = "(^|\\s)"; if (exactMatch) { prefix = "^\\s*"; } var rxSelector = new RegExp( prefix + selector.replace(/[$.(){}\[\]^]/g, "\\$&") + "\\s*$"); var hits = toArray(document.styleSheets).map( function (styleSheet) { return toArray(styleSheet.cssRules || styleSheet.rules).filter( function (rule) { return rxSelector.test(rule.selectorText); }); }).filter(function (hit) { return hit.length > 0; }); return _concat.apply([], hits); }; }()); var rulesets = Object.create(null); if (!rulesets["people"]) { rulesets["people"] = findRules(".people", true); } var rules = rulesets["people"]; if (rules.length > 0) { rules[rules.length - 1].style.fontWeight = "normal"; } PointedEars -- When all you know is jQuery, every problem looks $(olvable).