I have the following code
var aVar = "sample text";
alert(aVar);
$(this).replaceWith( "<input type='text' value=" + aVar + " id='laID' style='width: 100px; padding-right:20px; color:white;'/>");
The alert message box returns the expected value: “sample text”. However, the DOM element is generated with the following value: “sample”. Now, if i try it the following way it works:
$(this).replaceWith( "<input type='text' value='sample text' id='laID' style='width: 100px; padding-right:20px; color:white;'/>");
Unfortunately, i have no choice but to read the value from a variable, i can’t have it hardcoded. Hope someone can guide me with this! thankss
CHange:
To:
Attributes should be quoted.