I want to make a text clickable and by this I mean every word in it.
Now I know that you can wrap every Word with a <span>
tag. That works well for
sentences and paragraphs, but I want to be able use long texts (Articles to books) and I guess that this mechanism wont work for this.
So in a way I want to add the specific eventlistener, when I click on it and not beforehand, because wrapping each word in a whole book with a <span>
would just cause to much overhead.
So I was wondering if there is something like a package that can do that for me?
The other way I could think of, is to put the text and event Listeners into an Object like this:
[{"word: 'Hello'", event:EventListenerFunction},{"word":'World!', event: EventListerenerFunction},...]
.
This way I can compute the whole thing on the server and not on the client and would create a lot more information needed. It also has advantages for other stuff I want to do with the texts too.
Now the problem with this approach is the displaying. Its easy to display the text in vue.js like so: {{ textObject.text }}
(if the object is structured in the right way of course. Otherwise you need to filter the words beforehand). But How can I display the words without losing the information in the Object and make the event listeners work?
My third theoretical Idea was to give the parent html-tag an eventlistener that somehow gets the clicked word as argument. That would work with the wrapping span
around the words approach. But without it?
Do you have any other ideas?