When I try to pass select
tag with anchor
tags wrapped in the option
tags, the browser removes the anchor tags. Bard tells me that it is removed by an escape()
function in the browser. How can I prevent this from happening.
I pass this:
<select>
<option><a href="page1.html">Page 1</a></option>
<option><a href="page2.html">Page 2</a></option>
</select>
And the browser removes the anchor tags and uses this:
<select>
<option>Page 1</option>
<option>Page 2</option>
</select>
Some people say that it is not good practice to do what I am trying to do. But I don’t mind.
Please can somebody help me here?
2
Answers
Bard is telling you utter nonsense. There is no such function for you to suppress.
Option tags simply cannot contain anchor tags. It’s invalid markup.
You need to mind, because it’s not possible. The browser is doing its best to recover from invalid markup by stripping away the invalid part.
What you’re trying to do, which is wrapping anchor tags inside tags within a element, is not valid HTML and goes against standard web development practices. The behavior you’re encountering, where the browser removes the anchor tags, is expected because the content inside tags should be text only.