title: Javascript SyntaxError: unexpected token: identifier when using php's echo to execute javascript code
body: <p>So, i want to insert a div in the page when a specific condition arrives.
  I'm checking the condition in PHP like:</p>
  
  <pre><code>if ($var == 0) {
      echo '&lt;script&gt;console.log("Test.");
      var res = document.getElementById("response");
      res.innerHTML = "&lt;div class="hello"&gt;hi&lt;/div&gt;";&lt;/script&gt;';
  }
  </code></pre>
  
  <p>So, what i think is that the single and double quotes are mixed within each other and its giving SyntaxError on this piece of code</p>
  
  <pre><code>echo '&lt;script&gt;res.innerHTML = "&lt;div class="hello"&gt;hi&lt;/div&gt;"&lt;/script&gt;';
  </code></pre>
  
  <p>I tried writing </p>
  
  <pre><code>res.innerHTML = "&lt;div class='hello'&gt;hi&lt;/div&gt;";
  </code></pre>
  
  <p>but then the code doesn't work as i'm using it inside php's echo for which I'm using single quotes('').</p>
  
  <p>My basic goal here is to add a division with a class in my code if the condition satisfies. I'm checking the condition in PHP.
  Can you please tell me how can i avoid getting that error, as the following works fine.</p>
  
  <pre><code>echo '&lt;script&gt;res.innerHTML = "&lt;div&gt;hi&lt;/div&gt;"&lt;/script&gt;';
  </code></pre>