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