1

Initial HTML output that I get from wordpress:

<div class="testimonial-name">Syed Haroon {{ Web Developer_ India }}</div>

Below given jQuery code will convert {{ to <span> and }} to </span> and _ to ,

jQuery('.testimonial-name').text(function(index,text){
      return text.replace("{{",'<span>')
                 .replace("}}",'</span>')
                 .replace('_',',');
    })

After running the above code the result is:

<div class="testimonial-name">Syed Haroon &lt;span&gt; Web Developer, India &lt;/span&gt;</div>

What I actually need is:

<div class="testimonial-name">Syed Haroon <span>Web Developer, India</span></div>

2 Answers 2

2

Use html() instead of text

jQuery('.testimonial-name').html(function(index, html) {
  return html.replace("{{", '<span>')
    .replace("}}", '</span>')
    .replace('_', ',');
})
span{
  color:green;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="testimonial-name">Syed Haroon {{ Web Developer_ India }}</div>

Sign up to request clarification or add additional context in comments.

Comments

2

Use .html() instead .text():

jQuery('.testimonial-name').html(function(index,html){
    return html.replace("{{",'<span>')
        .replace("}}",'</span>')
        .replace('_',',');
});

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.