title: replace() with second parameter as a variable?
body: <p>My function is intended to replace a div with an image, and reset it back to the same div after a period of time. When replacing the div, there are custom HTML data- attributes that I need to add back to it, but using the replaceWith() method I have to set the div first and then replace it after. In this instance I need to update the 'data-x' and 'data-y' attributes, which will be stored as the first item in the arrays x_cord and y_cord. The first part of the function works as intended, the problem occurs at the setTimeout section.</p>
  
  <p>I have attempted to use a placeholder to replace with the value, named changex and changey. I can not get revert.replace("changex", x_cord[0]) to work as intended, or am I just not going to be able to do this? I have looked up my issue and have seen Regular Expression solutions but that only applies to the string that people are looking for, not the string that people want to change it to.</p>
  
  <p>tl;dr: I need to change 'changex' and 'changey' to x_cord[0] and y_cord[0].</p>
  
  <pre><code>function explode(e){
  var obj = $(e);
  var replacer = $('&lt;img width="25px" height="25px" src="http://i.imgsafe.org/c07fe0155d.gif" data-x="" data-y=""&gt;&lt;/img&gt;');
  obj.replaceWith(replacer);
  var found = $("#gameArea").find("img");
  setTimeout(function(){
      var revert = '&lt;div class="grass gameTile" data-component="" data-x="changex" data-y="changey"&gt;&lt;/div&gt;';
      var x = revert.replace("changex", String(x_cord[0]));
      x_cord.splice(0,1);
      var y = revert.replace("changey", String(y_cord[0]));
      y_cord.splice(0,1);
      $(found[0]).replaceWith(revert);
  }, 1200);
  </code></pre>
  
  <p>}</p>