Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problems toggling style.display values

Reply
Thread Tools

Problems toggling style.display values

 
 
Evertjan.
Guest
Posts: n/a
 
      10-27-2005
Matt Kruse wrote on 27 okt 2005 in comp.lang.javascript:

> Evertjan. wrote:
>>> function toggleTable(id){
>>> var tables = document.getElementsByTagName('table');
>>> for(i in tables) tables[i].className = 't';
>>> document.getElementById(id).className = '';
>>> }

>
> Setting a classname on a table is much slower than setting individual
> attributes, since the browser needs to re-compute all the nested tags'
> styles. It may or may not be the best route, depending on the
> situation.
>
>> Even nicer, IMHO:
>> function toggleTable(id){
>> var tables = document.getElementsByTagName('table');
>> for(i in tables)
>> tables[i].className = (tables[i].id!=id)?'t':'';
>> }

>
> Unless you are confident that your markup will never change, setting
> the value of className should be avoided, IMO. You should always add a
> classname from the space-separated list or remove it. That way, if
> your table has a class of "data" it would become "data t" rather than
> losing the "data" class entirely. Then the code becomes more portable
> and generalized.
>


I am sure you are right, Mat.

I like programming for fun and visual elegance,
that is why I wrote "nicer", not "better".

In general, getElementsByTagName is also not safe in the sense that later
alterations won't lead to coding bugs, and the best is id-ing all
elements that need to be addressed by one's code.

However the class="data t" is rumored not to be cross browser compatible?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      10-27-2005
Evertjan. wrote:
> However the class="data t" is rumored not to be cross browser
> compatible?


Not in any recent browsers that I know of. It's definitely part of CSS
specs.
Netscape 4 didn't like it, iirc, but who cares?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      10-27-2005
On 27/10/2005 20:33, Matt Kruse wrote:

> Evertjan. wrote:
>
>> However the class="data t" is rumored not to be cross browser
>> compatible?

>
> Not in any recent browsers that I know of. It's definitely part of CSS
> specs.


And HTML, which is where it matters.

CSS itself has its own, related issue where multiple class names are
used in a selector. That is:

.class1.class2 {
/* ... */
}

Even IE6 gets this wrong; it considers the last class name only.

> Netscape 4 didn't like it, iirc, but who cares?


Neither does IE4, and I share your sentiment. After all, CSS only
provides presentation suggestions.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      10-27-2005
Michael Winter wrote on 27 okt 2005 in comp.lang.javascript:

> Even IE6 gets this wrong; it considers the last class name only.
>
>> Netscape 4 didn't like it, iirc, but who cares?

>
> Neither does IE4, and I share your sentiment. After all, CSS only
> provides presentation suggestions.
>


I will start using it again.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to generate alternate toggling values in a loop? Debajit Adhikary Python 10 10-18-2007 05:47 PM
New characters added when toggling Between Design & HTML Mode in Web Form Editor timburda@hotmail.com ASP .Net 1 07-07-2005 08:38 PM
New characters added when toggling Between Design & HTML Mode in Web Form Editor timburda@hotmail.com ASP .Net 0 07-07-2005 05:54 PM
Toggling Image =?Utf-8?B?c2lhag==?= ASP .Net 1 05-06-2005 10:45 AM
Toggling display problems Jamie HTML 7 01-29-2004 01:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57