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

224
Views
Can I add a function with the (click) event to my span tags that I added with the replace method?

https://i.stack.imgur.com/B5doW.png I have sentences like this, and as you can see, if the word I'm looking for is in that sentence, I put it in span tags.

.replace(query.toLocaleLowerCase(), `<span>${query}</span>`,).toLocaleLowerCase()

(query is my search word) and I want to make the word taken in these span tags like this

`<span (click)="myFunction()">${query}</span>`

Is there a way to do this ?

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

0

Have you tried

.replace(query.toLocaleLowerCase(), `<span onclick="functionName()">${query}</span>`,).toLocaleLowerCase()
about 4 years ago · Juan Pablo Isaza Report

0

I got the solution like this, it's not quite right, but the simplest

TS Side

click(evt) {
const href = evt.target.localName;

if (href == 'span') {
  evt.path.forEach(element => {
    if (element.localName == "p") {
       ---my codes---
    }
  });
}

}

HTML side;

(click)="click($event)" [innerHtml]="subtitle"
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!