2

I'm not quite sure what I'm doing wrong.

Here's the Fiddle

section:not(#2) { font-size:33px; }

Update:

Forgot about not using numbers for the example!

Silly me, I was doing something like this and forgot the # before current. Pesky syntax errors.

current = $(this).attr('id');
$('section:not(#'+current+')').css('height',titleHeight);
Casey Dwayne
  • 2,069
  • 1
  • 14
  • 31

2 Answers2

5

Your id is invalid, id never starts with a number, you need an alphabet at the start

Demo

<section id="a1">Section 1</section>
<section id="a2">Section 2</section>
<section id="a3">Section 3</section>

CSS

section:not(#a2) { font-size:33px; }

Take a look at this answer for more details

Community
  • 1
  • 1
Mr. Alien
  • 140,764
  • 31
  • 277
  • 265
  • Forgot about not starting with numbers when I put together the example! This means it's something wrong in my jQuery. Thanks! – Casey Dwayne May 11 '13 at 19:20
  • I don't know how old the [official documentation](http://www.w3.org/TR/html-markup/global-attributes.html#common.attrs.id) is (might be after you posted your answer), but `id` attributes starting with a numeric character are now **valid in HTML5** (even if they're not in CSS). – Jeff Noel Jul 18 '13 at 14:59
2

You can't start your element Id with a number in CSS. There is a way around this, however, if you really need to have number Ids in your HTML, and that is by using a Unicode equivalent in the CSS, e.g.:

section:not(#\32) { font-size:33px; }

The Unicode number for the '2' character is 32. Here is a fiddle demonstrating this.

Holf
  • 5,149
  • 2
  • 36
  • 61
  • 1
    Well well this is dirty but this is good, what does `\32` do here? – Mr. Alien May 11 '13 at 19:19
  • The '\' denotes Unicode. 32 is the Unicode number for the '2' character. – Holf May 11 '13 at 19:20
  • @Holf Oh got it, you get my +1 :P, and -kcdwayne, no, its cool but it's not the right way :) – Mr. Alien May 11 '13 at 19:22
  • @kcdwayne I dunno, it sort of gets you out of a hole if you really, really need to have your element Ids starting with numbers. But it makes the CSS substantially harder to read. I'd always comment it to indicate what is going on. And I can't think of a really good reason why you'd have to stick with element Ids starting with numbers. – Holf May 11 '13 at 19:23
  • 1
    @Holf No doubt, but it shouldn't take away from your feat of making the 'impossible' possible ;). When using numbers I put an identifier in front (i.e. `#article-22`). – Casey Dwayne May 11 '13 at 19:27