Subscribe on changes!

attribute text on <a> element overwrites text

avatar
Sep 28th 2022

image redblobgames in the vue land discord also put out this, to help possibly narrow the issue.

avatar
Sep 28th 2022

This is a weird/funny edge case. The explanation is in the fact that Vue generally prefers to set values through element properties rather than element attributes. And anchor elements do have a textproperty which you can use to get or set the text of an anchor:

https://www.w3schools.com/jsref/prop_anchor_text.asp

if you wanted to set text specifically as an attribute even though achors do not have such an attribute as per the spec, you could do it like this:

https://sfc.vuejs.org/#eNp9jkluwzAMRa8icJNNLBVtV4YbpPfgRonZ1m01gKKdAIHvHjoTMgBZ6r8HPu3gM2c79AQ1NEIh/3uhBUaUxptaaCvWi/AHwsyv1i3NEBZfKTXOH6W2G8xkqXDgZ6y7Co27nIQ5dCEnlir4bH9LilrcYTQGT6Ag1OawTJt+aXoj/IjkUjvXx/z3bdcpuKUyx32ULlDVprB8s6/2/UWbRa53SyVUK06bQqxFhPnVcafjQFwxxZaY+Gnszr0J3rGH6NQcMY4w7gFKGH0q

avatar
Sep 28th 2022

if you wanted to set text specifically as an attribute even though achors do not have such an attribute as per the spec, you could do it like this:

It was actually an accidental passthrough of a prop using v-bind=$props to a dynamic child component that rendered an <a>. Was quite a pain to find, not knowing that the text property existed. Especially considering the mdn doesn't mention text

avatar
Sep 28th 2022

The linked MDN page documents the HTML element's attributes, and it doesn't have a text attribute

it does have a text property documented here, for its DOM interface: https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement

But yeah, agreed, it's an odd one that I also didn't know about until a couple of minutes ago :D