I am utilizing a div
with v-html
to showcase data fetched from a database:
<div id="Content" v-html="
${Content}"></div>
Inside the presented ${Content}
, there may be various a
tags linking to external pages. I aim to parse these and attach an @click
event handler to each one. For instance:
<p>Calm down, Marty, I didn't disintegrate anything. The <a href="example.com/m">molecular structure</a> of Einstein and the car are completely intact. They wanted me to build them a bomb, so I took their <a href="example.com/d">plutonium</a> and in turn gave them a shiny bomb case full of used pinball machine parts.
This needs to be transformed into:
<p>Calm down, Marty, I didn't disintegrate anything. The <a @click="validateLink()" href="example.com/m">molecular structure</a> of Einstein and the car are completely intact. They wanted me to build them a bomb, so I took their <a @click="validateLink()" href="example.com/d">plutonium</a> and in turn gave them a shiny bomb case full of used pinball machine parts.
Alternatively, I can direct Vue.js to execute the validateLink()
function whenever any a
tag is clicked within the div id="Content"
element.
To capture all the a
tags within the div
, I use the following method:
const AnchorTags = document.getElementById('Content').getElementsByTagName('a');
However, I am unsure how to proceed in triggering the validateLink()
function on clicking these tags.