I am using the following code in JavaScript’s document.write method:
<script type="text/javascript">
document.write("<font color="blue">["+time()+"]</font>");
</script>
But this doesn’t seem to work. How can I fix it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem has nothing to do with HTML directly, but simply with how string literals work in JavaScript (and pretty much every other programming language). If you want to use a
"character inside a JavaScript string that is delimited with"characters then you must escape it:\". Alternatively, use'to delimit either the string or the attribute values.That said, generating HTML using
document.writeusually isn’t a great idea (it only works at load time and is usually better replaced with more reliable server-side code or more reusable DOM manipulation)) and thefontelement is deprecated.