Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
append svelte component to HTMLCollection

I have string templates from users that looks something like this,

<div>hello this is a comment #344 funny #212 haha</div>

The numbers are referencing other posts. I use regex and turn the comment into something like this:

<div>hello this is a comment <a class="postlink>#344></a> funny <a classs="postlink">#212</a> haha<div>

What I am trying to do is when they hover over the post number, it will make a popup above their mouse showing the post that the tag is referencing. I have a <Post /> component but I am 100% lost on where to go from here..

I can get a list of the <a> tags by going

let quotes = document.getElementsByClassName('postlink');

and that gives me an HTMLCollection I can iterate over to give event listeners to each one, like this:

    [...quotes].forEach((q) => {
            q.addEventListener('mouseover', (e) => {
                console.log('mousing over q:', q);
            });
            q.addEventListener('mouseout', (e) => {
                console.log('mouse left q:', q);
            });
        });

        console.log(quotes);

This works, but I'm not sure how I can use the <Post /> component here, or if I would have to completely make another html template.. I tried asking this time with all of what I am trying to accomplish, but I'm still not even 100% sure what I'm confused about.. maybe someone has suggestions..

As you can see, the elements are embedded inside the users comment, so I cannot just replace the whole thing.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!