javascript - jQuery append adding extra qoute -


my code:

$("#thescreenshots").append("<img class='screenshotthumbnails'      onclick='openscreenshotmodal('"+datareturned['screenshots'][i]+"')'     src='/assets/screenshots/"+ datareturned['screenshots'][i] +"'>"); 

is outputting:

<img class="screenshotthumbnails" onclick="openscreenshotmodal(" 'img_0203.png')'=""      src="/assets/screenshots/img_0203.png"> 

why add weird qoute? , how can fix this?

you need escape of quotes. try this:

$("#thescreenshots").append('<img class="screenshotthumbnails" onclick="openscreenshotmodal(\''+datareturned['screenshots'][i]+'\')" src="/assets/screenshots/'+ datareturned['screenshots'][i] +'">'); 

it output this:

<img class="screenshotthumbnails" onclick="openscreenshotmodal('img_0203.png')" src="/assets/screenshots/img_0203.png">


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -