0

[![enter image description here][1]][1]I am using the below mailto Code to populate to, cc, bcc, subject and body fields in email application. I am binding the parameters that is coming from JSON response as below. In the below code, contentField I am getting from response as HTML code with some
tags. I need to remove the br tags and populate the fields in next line .

<a class="" href="mailto:{{toField}}?cc={{ccField}}&bcc={{bccField}}&subject={{subjectField}}&body={{contentField}}

Below is the HTML code from response and I am binding that to content in HTML.

'Please H F LUI DIGESTIVE AND LIVER CLINIC and +65 90119103 <br> 
Issues: </br><br>Doctor</br>MCR: 05572G'

What I want to achieve is :

'Please H F LUI DIGESTIVE AND LIVER CLINIC and +65 90119103
Issues:

Doctor MCR: 05572G'

1 Answer 1

1

You can parse HTML content using the below Regex as well.

// cleanText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
   cleanText = strInputCode.replace(/<.*?br.*?>/g, '%0D%0A');

JavaScript: How to strip HTML tags from string?

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

11 Comments

With this code, I am just able to remove the br tags, but i want to bring them to next line as well. I have edited my question , what i want to achieve
You can try like this code "<br/>Some<br/> HTML".replace(/\<br\/\>/g, '\r\n');
Could u pls edit your original answer, I am getting clearly with your above comment
Updated original answer
That doesnt work . I am getting <br> tags also in my output : Please H F LUI DIGESTIVE AND LIVER CLINIC and 65 90119103 <br> Issues: </br><br>Doctor</br>MCR: 05572G
|

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.