I was wondering if what I am trying to do is possible. I have a string variable and I need to put HTML comment in it like this:
var text = 'Some text. <!-- comment --> Some more text.';
The above code doesn't work, is there any way to do this?
Something like this?
var text = "Some text. <!-- comment --> Some more text.",
myDiv = document.getElementById('myDiv');
myDiv.innerText = text;
I'm curious as to whether that will actually hide the commented value, or will it also print out the <!-- [value] -->, as well?
Sorry, my bad. The code I have actually works. It looked like it didn't because of the color styling my text editor has. Thanks for your input on the topic.
Hot diggity. Never, ever, once thought about putting a comment within a string. Figured that because it's a literal, then the HTML wouldn't process <!-- and --> as code, rather it would as a string. Just played around with it. Very interesting.
This topic is now closed. New replies are no longer allowed.