Semicolons in HTML as Javascript String - SendGrid

I am using the SendGrid API to send html emails from my site using the following function:

function sendFormData2() {
 const subject = `Test HTML Email`;
 const body = "<p>Hello<span style='color: #ff0000;'><strong>World</strong></span></p>";

    sendEmail2(subject, body)
        .then(response => console.log(response));
}

The email sends successfully but reads as follows:

This is due to the semicolon in the code after #ff0000. In this example I could remove the semicolon but there will be examples where a semicolon is required to separate multiple html styling parameters. When I remove the semicolon, the body of the email looks as follows (the way I want it to):

I thought I could use semicolons freely in a string but it seems to be terminating the line of code. Can anyone advise?

Hi, Iain Downer . This is WAG; does it work if you replace the assignment of the body constant with the following:

const body = '<p>Hello<span style="color: #ff0000;"><strong>World</strong></span></p>';

? (I “inverted” your use of apostrophes and double quotes.)

If that doesn’t work, I’m wondering if JavaScript is considering that the end of the statement and, as a result, the internal semicolon needs to be escaped (i.e., preceded by a backslash) as follows:

const body = '<p>Hello<span style="color: #ff0000\;"><strong>World</strong></span></p>';

or:

const body = "<p>Hello<span style='color: #ff0000\;'><strong>World</strong></span></p>";

?

Unfortunately neither of those work - I tried escaping already but my understanding is that you shouldn’t need to escape semicolons.

Try backticks and make sure SendGrid’s body type is set to html in the api call

const body = `<p>Hello<span style='color: #ff0000;'><strong>World</strong></span></p>`;

Try unicodes:
here are some unicodes for ‘;’
U+0003B
;
;
;
\003B

If your mail is still getting chopped off after semicolon try removing the semicolon at the end of the unicodes:
U+0003B
&#x3b
&#59
&semi
\003B

If it still doesn’t work, Ion know no more. I’m then guessing its from they side.

Hi @iaindowner , were you able to find some solution for this? I’m stuck at the same issue.