0 votes
in Education by (1.7m points)
i want to add image inside a span here's what i tried (inside a form i added this script):

<script language="JavaScript">

       function addSelected(){

             var content=" <img src='/resources/images/image.bmp'/> ";

             var span = document.getElementById("members");

             span.innerHTML=content;

              }

          </script>

but it always gives me the error:

unterminated string literal

on this line:

var content=" <img src='/resources/images/image.bmp'/> ";

because it's translated by browser to something like (found that by firebug):

var content=" <img src="/resources/images/CONTACTS.bmp" /> &#34;;

this is tested on firefox 8.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
Simply add \ before any " in the content string.

var content=" <img src=\"/resources/images/image.bmp\"/> ";
...