I'm trying to build a HTML string in the following way:
htmlString = '<html>';
var headerString = "image1";
var sImage = "Android_images/"+headerString+".png";
htmlString += '<img src='+sImage+' />';
htmlString = '</html>';
I need to dynamically append a image string, but it shows:
<img src=Android_images/dfdfd.png />
The concat() method joins two or more strings. The concat() method does not change the existing strings. The concat() method returns a new string.
The best and fastest way to concatenate strings in JavaScript is to use the + operator. You can also use the concat() method.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
In javascript the "+" operator is used to add numbers or to concatenate strings. if one of the operands is a string "+" concatenates, and if it is only numbers it adds them.
You're re-setting the variable on this last line:
htmlString = '</html>';
Add a +
and it'll work:
var htmlString = '<html>';
var headerString = "image1";
var sImage = "Android_images/" + headerString + ".png";
htmlString += '<img src="' + sImage + '" />';
htmlString += '</html>';
Also, why are there <html>
tags here?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With