48 ms·
> What is the actual use of grabbing an element that has an ID that matches the URL hash? Ha! Browsers do that by default. On page load, they scroll to an anch
by paulddraper 8y ago
> What is the actual use of grabbing an element that has an ID that matches the URL hash?
Ha! Browsers do that by default. On page load, they scroll to an anchor tag with the id of the URL fragment.
I could imagine some JS-driven dynamic loading/scrolling using the same convention.
- throwaway2016a 8y agoBrowser do it based on name="" on anchor tags not ID. And if you are implementing your own version you should probably also be using name not ID. Best practice is t use JS to progressively enhance the page not reinvent the wheel so name is the logical choice. Edit: Also, word of advise. Lose the "Ha!"... it could potentially make your comment come across as arrogant. Edit 2: Leaving my original comment intact even though I was wrong. Apparently my knowledge is out of date on this one. Thank you "re" for correcting me.
- re 8y ago> Browser do it based on name="" on anchor tags not ID Fragment identifiers can refer to elements by ID; this has been supported by browsers for over a decade and is the preferred way to specify a target: https://www.w3.org/TR/html4/struct/links.html#h-12.2.3 https://www.w3.org/TR/html4/struct/links.html#h-12.2.3 In fact, `<a name="">` is now considered obsolete: https://www.w3.org/TR/html5/obsolete.html#obsolete https://www.w3.org/TR/html5/obsolete.html#obsolete
- throwaway2016a 8y agoThank you. That is good to know. I really appreciate this info and the links. I'll file it under "things I learned 20 years ago that are now obsolete :("