html - Quotes issue in Javascript -


i want refresh img element within div every 5 seconds indicate whether user connected internet or not connected. if user connected, display image online, if user offline, local image display.

however, cannot around quote problem. tried "&-quot;" thing (without dash) , still not work. here code:

<script type="text/javascript">     window.setinterval("refreshdiv()", 5000);     function refreshdiv(){     document.getelementbyid("test").innerhtml = "<img id="this" src="http://stallionware.weebly.com/uploads/3/0/4/3/30431988/4901948_orig.png" onerror="this.src='nowifi.png'">"; } </script> <div id=wifi> <img id="this" src="http://stallionware.weebly.com/uploads/3/0/4/3/30431988/4901948_orig.png" onerror="this.src='nowifi.png'"> </div> 

i not have desire use jquery or ajax or server-side languages because on local machine.

you can escape double quotes this:

document.getelementbyid("this").innerhtml = "<img id=\"this\" src=\"http://stallionware.weebly.com/uploads/3/0/4/3/30431988/4901948_orig.png\" onerror=\"this.src='nowifi.png'\">"; 

by typing \" you're telling javascript want insert double quote inside string. other option have use single quotes instead. (i've changed getelementbyid 'test' 'this' since html has no 'test' id)

also, shouldn't call function using string did on refreshdiv. instead should call name this:

window.setinterval(refreshdiv, 5000); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

Bubble Sort Manually a Linked List in Java -

asp.net mvc - SSO between MVCForum and Umbraco7 -