I'm wondering if it is possible to link to something that has more than 1 id?
For example: I want to link to a h4 tag using one id or another id but I want them to link to the same tag. Something like:
<h4 id=1 id=2>Title</h4>
So that the h4 tag can be linked to with #1 or #2
Is there anyway to do that?
No. It's not possible to have more than one id attribute of an element. As you have given like-
<h4 id=1 id=2>Title</h4>
Here the 1 will be accepted and rest of the value will be ignored. The w3c has given specification here. And the value for id attribute can be given as specified here
This is a deficiency in HTML.
It's often desirable to have multiple "nicknames" for the same element, when using IDs as anchors. For instance, this happens a lot when refactoring web pages while trying not to break old links. Unfortunately, HTML doesn't support multiple ID attributes on the same tag.
Another example is the glossary on my web site, where you can link to the entry for any word by appending #word to the glossary page's URL. So what are we to do when there are two words or two common spellings of a word defined at the same glossary entry?
My workaround for this problem is to make an empty SPAN block for the second ID:
<li id=color><span id=colour></span>Characteristic wavelength or...
It works for my use case, but it sure is ugly (made even uglier by the fact that you can't use an XML-style self-closing tag syntax, like <span id=synonym />, and it doesn't solve the problem when you need to refer to the element from javascript via document.getElementById().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With