I have a div in my application with an id of financial[terms]
, but jquery does not seem to be able to target this.
Is this a semantically invalid id?
I have a div in my application with an id of financial[terms]
, but jquery does not seem to be able to target this.
Is this a semantically invalid id?
According to w3.org:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
So, no, your id is not semantically valid.
The HTML 4.01 spec states that ID tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).
To precisely answer your question, your id
is invalid in HTML 4.01
According to this article, in HTML 5 however, your id
looks like it could be valid.
EDIT:
It should be noted that jQuery itself may still have some trouble with certain aspects of a valid HTML 4.01 id
, such as periods and colons.
Is this a semantically invalid id?
I would say yes, use something more like financial-terms
.
While it's invalid in IDs (but fine in name attributes), you can probably get away with it if you want. You need to escape special characters, as the square brackets have their own meaning in jQuery selectors.
This is most definitely invalid. An id can start with a letter, and be followed by letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_").
Id naming rules from W3.org:
[A-Za-z]
[A-Za-z],[0-9],"-","_",":" or "."
If you can't change the ID
, you can still use document.getElementById
inside jQuery or (worse performance) use $("[id='financial[terms]'")
.