3 ms·
Why are you suggesting the #foo header have a link to itself? That doesn't make sense. An id attribute value is supposed to be unique to a document, they also a
by giantrobot 6y ago
Why are you suggesting the #foo header have a link to itself? That doesn't make sense. An id attribute value is supposed to be unique to a document, they also act like anchors. Your <h2 id="foo"> is already the #foo anchor target. You can add arbitrary anchors with the "<a name>" tag but if you've got elements with id attributes you're already good for anchors.
This is true of all elements with an id attribute, not just headers. They're unique in the document so they can be unique selectors in the DOM.
- JimDabell 6y ago> Why are you suggesting the #foo header have a link to itself? This is already the way that page is set up; grandparent was merely explaining a better way of doing it. As for why you would want to do this – it’s very common for headers to include links to themselves so that readers can easily obtain a link to share with others. But as grandparent points out, it’s more common to do this with a symbol next to the heading rather than turn the entire heading into a link. This technique has been in use since about 2004: https://www.tbray.org/ongoing/When/200x/2004/05/29/PurpleNumbers https://www.tbray.org/ongoing/When/200x/2004/05/29/PurpleNum...
- giantrobot 6y agoThat makes sense but was poorly described in the GP comment. I've seen this plenty of times but the justification wasn't jumping out at me. I think the example of the blockquote having a header id of "blockquote" didn't really help with clarity, especially since there's multiple blockquotes.
- infogulch 6y agoIt's so frustrating when you want a link to a specific heading but the site doesn't have these links. So much online documentation has the ids but not the links. How else are you supposed to find the ID to link to a heading? Guess? Open dev tools? I will do both, because I'm particular about it, but 99.9% of regular people I know don't care enough to try either. But if it's right there (and they know what it is and what to look for), then maybe there's a chance someone will give me a direct link to the specific part of the docs under question instead of another enormous pre-compiled single page document with vague instructions to search on the page for what turn out to be frequently used terms. Please make linking to content headings easy on your site!