json - using anchot tags and href in jquery prepend and append -


i'm trying append anchor tag div id #photo. href contains key pair data hyperlinks. correct way write line of code.

ideally want line of code follows

 $('#photo').prepend('<a href="javascript:pixlr.edit({image:'http://mysite.com/photo    /+'photo'+', title:'+photo+', service:'express',exit:'http://mysite.com', method:'get', locktarget: 'true', target:'http://mysite.come/upload', locktitle :'true'});" id="uploadedphotoedit" title="click enhance photo before sharing"></a>'); 

photo jquery variable holds name of uploaded photo. how use jquery variables , use hyperlinks without hyperlinks know simple '+nameofvariable+' introduction of hyperlinks use double quotes becomes difficult.

thanks

one way make json object use json.stringify make object string. if plan on having usable browser not support json.stringify, need include following js file: https://github.com/douglascrockford/json-js

var photo = "photo.gif";  var pixlrjson  = {     image : 'http://mysite.com/photo/' + photo,     title : photo,     service : 'express',     exit : 'http://mysite.com',     method : 'get',     locktarget : true,     target : 'http://mysite.come/upload',     locktitle : true };  $('#photo').prepend("<a href='javascript:pixlr.edit(" + json.stringify(pixlrjson) + ");' id='uploadedphotoedit' title='click enhance photo before sharing'></a>"); 

if not solution can escape quotes using backslash.

var test = "this test string has \" inside of it"; 

another alternative use double quotes inside of single quoted string:


Comments