HTML can use a “#name” link to direct users to named anchor elements, like <a name="name">. Is it possible to link to any other attributes, like id or class? How about HTML5 stuff like ‘itemprop’ or ‘content’ ?
HTML can use a #name link to direct users to named anchor elements, like
Share
Yes, and indeed it’s preferred to use the
idof an element to create an internal link within a page.Example markup:
JS Fiddle demo.
It’s worth noting that a link can connect to only one, unique, target, therefore a
class(or other attribute) cannot be used as all non-idattributes may be shared/replicated across many elements. Whereas anidmust be unique within the document.