== The _id_ attribute considered dangerous I've been doing various overhauls of DWiki recently (a faster and better DWikiText to HTML renderer written by Daniel Martin (and hacked by me, so blame me for any problems) went in tonight, for example). As part of this, I've been looking at the HTML DWiki generates, running it past HTML Tidy and the [[W3C validator http://validator.w3.org/]] and so on. It's been a learning experience. One of the things I've learned is that almost everywhere DWiki code and templates were giving _
_s an _id="..."_ attribute, it was the wrong thing to do. In something like DWiki, _id_ elements are *dangerous*. The problem for a dynamic, template driven site is that every (hard-coded) _id_ is a promise that that particular element will only ever appear ~~once~~ in a page. Any page. *Every* page. Better not forgetfully reuse an _id_-containing template twice in some page, even if it's the structurally right thing to do. (For instance, the
around all of the comments on a page used to have an _id_. That seemed harmless until I thought about a) possibly showing comments by default on pages and then b) the blog view, which would show multiple pages in their normal rendering glommed into one bigger page. Kaboom!) In DWiki's case, using _id_ wasn't getting me anything I couldn't get with _class_; CSS styling can use either. This made my use of _id_ more or less gratuitous, which just made my mistakes with it all the more wince-inducing. (The height of hubris was having a renderer, not even a template, put an _id_ in its output.) (I'm sure that advanced CSS tricks care about the difference, but DWiki's use of CSS is pretty simple.) After a bunch of revisions, I now have _id_ attributes in only five places, and at least two of them (the page header and the syndication feed information) are probably still mistakes. (They persist because I'd have to revise the CSS too, and I've already made enough big wrenching changes today.) PS: changing the DWikiText renderer caused some fiddly little changes in the HTML of every entry in CSpace's syndication feeds. If your feed reader exploded as a result of this, you may want to get a better one. (With a very few minor exceptions, there should be no visual differences.)