Unable to display background image using javascript on qualtrics -


for starters, have absolute no knowledge javascript. trying display background image extracted url address on page of questionnaire on qualtrics following codes:-

qualtrics.surveyengine.addonload(function() {     <div id="divtest">hello</div>     <img id="imgtest" />     <img id="imgreal" src="http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.jpg" />      var string = 'http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.jpg';     document.getelementbyid("divtest").style.backgroundimage = "url('" + string + "')";     document.getelementbyid("imgtest").src = string;   }); 

but got following error message:-

invalid javascript! cannot save until fix errors: unexpected token <

how go fixing this?

you cannot add html directly in javascript code, have create body section of page, or if need create elements via code have use createelement

var _div = document.createelement('div'); _div.id = 'divtest'; _div.innerhtml = 'hello'; _div.style.backgroundimage = "url('" + string + "')"; document.getelementsbytagname('body')[0].appendchild(_div); // place child of body 

or

document.getelementbyid('[id of parent element]').appendchild(_div); // place child of other element. 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -