Chung Do Chung Do - 1 year ago 58
jQuery Question

How to specific variable value inside "" javascript

My code

success: function(result) {
var htmlString = '';
htmlString+= '<div class=\"row mgt45 bg-delete\"><div class=\"col-sm-5\"><div class=\"p-relative\"><img id=\"logoImg\" src=\"result.image\" width=\"100%\"><button id=\"\" class=\"change-img topleft\" data-toggle=\"modal\" data-target=\"#myModal\"><i class=\"fa fa-camera\" aria-hidden=\"true\"></i> 画像</button></div> </div><div class=\"col-sm-7 corp-office\"><h2 id=\"\" class=\"changeableFacility\" contenteditable=\"true\">result.title</h2><p id=\"\" class=\"changeableFacility\" contenteditable=\"true\">result.content1</p><p id=\"result.content2\" class=\"changeableFacility\" contenteditable=\"true\">result.content2</p></div><span id=\"\" href=\"\" class=\"btn-delete\"><i class=\"fa fa-times-circle\" aria-hidden=\"true\"></i></span> </div>';


How can I store
as a variable instead of string?

Answer Source

Use ECMAScript 2015's Template String Literals

var id = 5;
var image = "myimage.jpg";
alert(` <div id=\"${id}\">`);
alert(` <img src=\"${image}\">`)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download