Javacript in html - Using single quote inside another single quote

Posted by Ashish Nair on Stack Overflow See other posts from Stack Overflow or by Ashish Nair
Published on 2010-01-08T09:12:44Z Indexed on 2010/04/18 17:33 UTC
Read the original article Hit count: 592

Filed under:
|
|
|
document.getElementById("img").innerHTML="< img src='/sitepath/"+imgg+".jpg' width='72' height='44' onclick='alert('hello');' />";

The above code is my javascript. Problem is printing hello or any other string. If I just type 123 in place of hello, it does give alert. But am not able to use a string like hello there. Normally a string in an alert function is kept inside quotes ' ' but the entire content is inside double quotes and I have already used single quote at the beginning of onclick function. I tried using Escape character ("\") but it didnt help. Any suggestions?

© Stack Overflow or respective owner

Related posts about single

Related posts about quote