or azran or azran - 11 days ago 5
Node.js Question

Convert Simple String Variable To HTML

I know this should be super simple but I can׳t get it work like i expect.
In my

Node.js
program I have a string
var
that is generated from some parameters.

var generatedString = "some string" + "other string";


I want to pass this variable to a method as
html
field so I used :

'<b>generatedString</b>'


When it print out to the browser I see: generatedString not its content.
What is the simplest way to make it work?

Answer

Use the same principle as in your first example.

'<b>' + generatedString + '</b>'

Or as parameter to a method

alert('<b>' + generatedString + '</b>');

Use it in a variable like this

var htmlString = '<b>' + generatedString + '</b>';
alert(htmlString);
Comments