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

229
Views
bind svelte elements from {@html} directive

I'm trying to take user input and find all the texts that look something like this >>523 like imageboards do. I convert these to HTML template strings through the regex replace method and sanitize the string. then I put the string in to svelte with {@html input}. It works very well but I have a few issues.

Here is the link to a REPL https://svelte.dev/repl/737a125144474234a100cd871c1d4d5b?version=3.42.6

If you look in the console (for some reason it makes me use devtools console, repl console does not work) you can see it gets me the two a elements there, but the forEach method does not work

I want the created element to link to the referenced post. but one post can have many quote link elements in it. and I have no idea how to get a variable reference to them because I can't use {#each} and I tried this inside onMount:

let quotes = document.getElementsByClassName('postlink');
        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);

And it gives me a type error in the console.

Uncaught TypeError: quotes.forEach is not a function

How can I accomplish this? I want the mouseover and mouseout events to show a preview of the post the quotelink links to.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.getElementsByClassname returns a NodeList object which doesn't have the forEach function defined, you can parse it to an array like this [...quotes].forEach

about 4 years ago · Juan Pablo Isaza Report
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!