title: How to escape JSON in an HTML string stored as a Javascript variable?
body: <p>I'm trying to parse a JSON string and I can't get it to work because of illegal chracters - which I cannot find...</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>make = function (el) {
      var config = el.getAttribute("data-config");
      console.log(config);
      var dyn = $.parseJSON(config)
      console.log(dyn);
  }
  
  var a= document.createElement("&lt;a href='#' class='template' data-config=\"{'role':'button','iconpos':'left','icon':'star','corners':'false','shadow':'false', 'iconshadow':'false', 'theme':'a','class':'test', 'href':'index.html','text':'Star Icon', 'mini':'true', 'inline':'true'}\"&gt;Star Icon&lt;/a&gt;");
  console.log(a);
  make(a);
  </code></pre>
  
  <p>I'm not really sure how to correctly unescape the JSON in my original string "a", so that it works.</p>
  
  <p><strong>Question_:</strong><br>
  Which quotation marks do I need to escape to get this to work?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong>  </p>
  
  <p>Ok. I figured it out using <code>Jquery</code> (I'd prefer Javascript-only though). This works:</p>
  
  <pre><code>make = function (el) {
      var config = el.attr("data-config");
          console.log(config);
      var dyn = $.parseJSON(config)
          console.log(dyn);
  }
  
  var c = $('&lt;a href="#" class="template" data-config=\'{"role":"button","iconpos":"left","icon":"star","corners":"false","shadow":"false", "iconshadow":"false", "theme":"a","class":"test", "href":"index.html","text":"Star Icon", "mini":"true", "inline":"true"}\'&gt;Star Icon&lt;/a&gt;')
  console.log(c);
  make(c);
  </code></pre>
  
  <p>So escaping the start/end quotations of the JSON string seems to do the trick. The actual problem was that I can not use <code>document.createElement</code> with a full string. I can only create the element <code>document.createElement(a)</code> and then set <code>innerHTML</code>. Need to look into this some more.</p>
  
  <p>If someone can tell me a Javascript-only way how to do this, please let me know.</p>
  
  <p>Thanks! </p>