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

113
Views
about replace methods in string in js
let code = document.querySelector('.Nform').innerHTML;
localStorage.setItem('code',JSON.stringify(code));
let finalCode = code.replace(/ <p class="removeElement" onclick="removeElement()"></p> /g , ` ` );
console.log(finalCode);
document.querySelector('.code').value =`${finalCode}`;

Hello , I want to use / /g to replace this html element from code but p tag have close element (/p) so how can escape it make sure i want to send this by code no sting, thanks

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

0

I think it's because of the parentheses, they should be escaped too. please try this: let finalCode = code.replace(/</div>/g, ' '); –

by GrafiCode https://stackoverflow.com/users/5334486/graficode

about 4 years ago · Juan Pablo Isaza Report

0

In your regex, You have to escape these four special characters : ", (, ), /

Demo :

let originalCode = document.querySelector('.Nform').innerHTML;

console.log(originalCode);

let finalCode = originalCode.replace(/<p class=\"removeElement\" onclick=\"removeElement\(\)\">Paragraph 1<\/p>/g, '');

console.log(finalCode);
<div class="Nform">
  <p class="removeElement" onclick="removeElement()">Paragraph 1</p>
  <p>Paragraph 2</p>
</div>

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!