[Javascript] multiple id CSS selectors [WAS: Mapping Image]

Paul Novitski paul at juniperwebcraft.com
Thu Sep 14 14:46:07 CDT 2006


>>On Thu, 14 Sep 2006 08:05:11 -0700
>>  Paul Novitski <paul at juniperwebcraft.com> wrote:
>By the way, this style rule is redundant:
>         #picture A#part1 {...}
>Because Ids are unique on the page, there can be only one #part1, so 
>you don't need to specify its parent.


At 9/14/2006 11:29 AM, Mike Dougherty wrote:
>Do you think the redundancy has a negative impact on performance 
>that outweighs the increased readability that this notation 
>provides?  Aside from the unlikely case of needing to arbitrarily 
>increase specificity by doubling up the Id the selector, I think it 
>can be useful to identify for the developer that the ID selector is 
>a child of another element in the markup.
>
>Is there a reason I should specifically NOT do that?


Not that I know of.  I haven't ever looked under the hood at a 
browser's DOM-parsing code so I can't say for sure, but if there is a 
difference I'm sure it can be measured in microseconds or 
milliseconds and therefore isn't significant for us big, slow-moving humans.

I was just pointing out the redundancy suspecting that the poster may 
have been new to CSS and thought it was necessary.  I enjoy the 
elegance of minimalist code and enjoy stripping out anything unnecssary.

But what's necessary?  I agree with you completely.  My philosophy is 
that script is for humans (computers would be content with binary 
machine language) and that its human readability should be one of the 
highest priorities for stylistic decisions.  I do occasionally use 
double id selectors when it helps me remember context.

Another use of multiple id selectors is in dynamic websites when the 
ancestral context of a given element can change from one page to 
another or from one event to another, where it might be desireable to 
distinguish, say, between:

         #navbar li#home
and:
         #sidebar li#home

or between:

         body#gallery li#home
and:
         body#contact li#home


I fear that we've strayed off-topic...

Regards,
Paul 




More information about the Javascript mailing list