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

166
Views
How to replace span tags with its own class name inside paragraph

I want to replace all <span></span> tags with their own class name inside the dynamic paragraph.

Example:

My paragraph is: "Welcome <span class="emo 1f4a9"></span> to our home <span class="emo 1f47b"></span>"

And I want the result: "Welcome 1f4a9 to our home 1f47b"

So I tried many ways but can't be got the class name of span. The paragraph comes from an ajax request as a text format for my public comment section and I will show it also as a push notification.

I tried

spantoemo('Welcome <span class="emo 1f4a9"></span> to our home <span class="emo 1f47b"></span>');
function spantoemo(MSG){
var element = $(MSG);   
element.find("span").each(function(index) {
        var A = $(this).attr('class');
        var B = A.replace("emo ", ""); 
        //var JAVACODE = toUTF16(parseInt( A, 16 )); var FINAL =  html.replace(/<span class="+A+"><\/span>/g, JAVACODE);
        var FINAL =  html.replace(/<span class="+A+"><\/span>/g, B);
});
var newString = element.html(); //get back new string
alert(newString);
}

And fiddle

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

0

function replaceSpans(string) {
    return string.replace(/<span class="emo (\S+)"><\/span>/g, '$1');
}

This seems to be giving the results you want.

Putting it into your example:

spantoemo('Welcome <span class="emo 1f4a9"></span> to our home <span class="emo 1f47b"></span>');
function spantoemo(MSG){
    MSG = MSG.replace(/<span class="emo (\S+)"><\/span>/g, '$1');
    alert(MSG);
}
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!