9

I was browsing a site and found this line of code:

<div class="section slideshow" id="/featured/">

I've never seen slashes in an id tag before, is this poor coding, a problem written out by the database, or something else?

GT22
  • 503
  • 1
  • 8
  • 25
  • 1
    This would not have been valid in prior to HTML 5, but is now. The id could be generated from an XPATH style location which would guarantee uniqueness but it is purely a guess. – detaylor Aug 02 '12 at 09:23
  • just visit [W3C](http://www.w3.org/TR/html401/types.html#h-6.2) fore more details... – Doc Roms Aug 02 '12 at 09:41
  • @Doc These are the html4.01 specs and are not applicable on html5 where [these restrictions have been removed](http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#the-id-attribute). – Christoph Aug 02 '12 at 10:09
  • The best thing would probably be to ask the person who wrote this... – Christoph Aug 02 '12 at 14:13

8 Answers8

5

Slashes in an id attribute is not a valid character:

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 (".").

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
Danny Brady
  • 1,895
  • 4
  • 20
  • 30
  • Not true for html5! [`The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.`](http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#the-id-attribute) – Christoph Aug 02 '12 at 09:41
  • It still validates correctly though when using ? I know it is not a valid character as said. Thought I would just mention that it does validate correctly still though. To what purpose why this would be used I don't know. Cheers – Danny Brady Aug 02 '12 at 09:56
  • The character is valid! The html4.01 restrictions have been removed in 5. – Christoph Aug 02 '12 at 10:07
3

Maybe to use it directly in an url and/or with javascript...

Phebus40
  • 173
  • 13
2

Maybe he use this method for insert to database(insert id in a string) or go to an url .

Slashe is not a valid character for ID in html 4.01 but its valid in html5 .

For html 4.01

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 (".").

Reference : What are valid values for the id attribute in HTML?

http://www.w3.org/TR/html5/global-attributes.html#the-id-attribute

Community
  • 1
  • 1
RAN
  • 1,443
  • 3
  • 19
  • 30
1

there is much reason for such a process, even if it turns out that this is not common, developer have the choice to appoint this class and id name :

Maybe he use this method to differentiate the same Id name without slashes,

Maybe he use this method for insert this id in a string for

  • insert to database.
  • go to an url.
  • other coding justify...

Maybe is just a CMS or Framework's nomenclature...

The same solution is to contact the website creator for to ask this question...

But, If you want more details, visit W3C namming Nomenclature website...

Doc Roms
  • 3,288
  • 1
  • 20
  • 37
0

I emailed the site and the owner replied.

The site is HTML4/ASPX and uses that slashed variable when called by Javascript to display a slide show.

He didn't seem to care that it wasn't valid, but it was working ok in all browsers.

GT22
  • 503
  • 1
  • 8
  • 25
-1

check the below program , id is just to refer that particular tag , its not necessarily nedd to be in a particular format ,

<html>
<head>
<script type="text/javascript">
function displayResult()
{
document.getElementById("/myHeader/").innerHTML="Have a nice day!";
}
</script>
</head>

<body>
<h1 id="/myHeader/">Hello World!</h1>
<button onclick="displayResult()">Change text</button>
</body>

</html>

the above program will give you better understanding

Esh
  • 836
  • 5
  • 16
  • 43
-1

HTML5 allows almost any value for the id attribute – use wisely

HTML 4.01 is pretty restrictive regarding what values are allowed for id attributes: 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 (“.”).

http://www.456bereastreet.com/archive/201011/html5_allows_almost_any_value_for_the_id_attribute_use_wisely/

Prashobh
  • 9,216
  • 15
  • 61
  • 91
-1

Attributes for an element are expressed inside the element’s start tag. Attributes have a name and a value.

There must never be two or more attributes on the same start tag whose names are a case-insensitive match for each other.

The following list describes syntax rules for attributes in documents in the HTML syntax. Syntax rules for attributes in documents in the XML syntax. are defined in the XML specification [XML].

Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, """, "'", ">", "/", "=", the control characters, and any characters that are not defined by Unicode. XML-compatible attribute names are those that match the Name production defined in the XML specification [XML] and that contain no ":" characters, and whose first three characters are not a case-insensitive match for the string "xml". Attribute values can contain text and character references, with additional restrictions depending on whether they are unquoted attribute values, single-quoted attribute values, or double-quoted attribute values. Also, the HTML elements section of this reference describes further restrictions on the allowed values of particular attributes, and attributes must have values that conform to those restrictions.

For more information see http://dev.w3.org/html5/markup/syntax.html#syntax-attributes

Prabhavith
  • 458
  • 1
  • 4
  • 15