Are dashes/hyphens safe for ID names?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Are dashes/hyphens safe for ID names?

Post by Sindarin »

I must say I am really confused, I have been reading articles on what is allowed and not when giving HTML elements, IDs.

I want to use:
<input type="checkbox" class="checkbox" id="my-option" name="my-option" />

Is it safe to use dash/hyphen in the ID? It doesn't generate an error for me but I've read some people saying JavaScript could treat "my-option" as "my minus option".
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Re: Are dashes/hyphens safe for ID names?

Post by Charles256 »

Not if it's in quotes as it should be. At least to the best of my knowledge. If someone knows otherwise a demo would be great.
Post Reply