4

how can i select div?

<div id="languageForm:j_id427:0:j_id432">Test</div>

this code does not work

#languageForm:j_id427:0:j_id432 { color:#00aa00; }

. . . . . . . . . . . . . . . . . . .

0

2 Answers 2

8

: is a special character in CSS (:hover)

Use \00003A to escape it:

#languageForm\00003Aj_id427\00003A0\00003Aj_id432 { color:#00aa00; }

jsfiddle

Note: Don't use \: because it doesn't work in IE7.

Why the many 0s? Because the browser will try to read at most 6 characters to parse a unicode constant in CSS files. Without the zeros, it would read \3Aj and stop with an error.

0
2

Your selector contains : so you need to escape them using a backslash \, use this

#languageForm\:j_id427\:0\:j_id432 { 
     color:#00aa00; 
}

Demo

Note: May be older browsers will fail in escaping, in this case you can use \3a which is colon equivalent.

#languageForm\3a j_id427\3a 0\3a j_id432 { 
    color:#00aa00; 
}

Demo (Note the spaces after \3a)

(Consider referring aarons answer if you are going with (\3A) solution)

6
  • Note: This doesn't work in IE7. Commented Jul 16, 2013 at 8:56
  • @AaronDigulla I was just creating a fiddle with \3a :)
    – Mr. Alien
    Commented Jul 16, 2013 at 8:57
  • I don't like the space after the Unicode escape; it messes with the syntax highlighting of almost any CSS editor. Commented Jul 16, 2013 at 9:09
  • @AaronDigulla yea its kinda confusing but i went for the shorter syntax :)
    – Mr. Alien
    Commented Jul 16, 2013 at 9:15
  • \3a\j... works (i.e. use a \ instead of a space) but you'd have to use \30 instead of \0 which would be confusing as well. Commented Jul 16, 2013 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.