Hacker News new | ask | show | jobs
by sbarre 4602 days ago
but then wouldn't document.getElementById() calls get confused, even though your IDs are nested?

Shouldn't it be the other way around?

    #homer .left-eye { ... }
    #bart .left-eye { ... }
makes more sense to me than

    .homer #left-eye { ... }
    .bart #left-eye { ... }
2 comments

  .homer #left-eye
This indeed makes (almost) no sense. It makes no sense for sure if you intend to have several characters on the page — id must be unique, and it does not matter that something is in front of it.

.some-class #some-id makes sense only if you want to style page-unique elements differently in some cases but even in that case I'd argue that #some-page-id #some-id would be better (assuming #some-page-id is the body element id).

The calls to JavaScript functions that are ID-based would certainly not work. But there are many ways to access them that wouldn't.

In regard to the selector type, does Homer have more than one left eye? More than likely not, but that's why I suggested using all class selectors as an option. Using all class selectors would enable you to produce (a) as many Homers as you'd like and (b) as many left eyes, right eyes, mouths, etc as you'd like.