title: How can one write correct HTML to an inline Javascript inside a JSP?
body: <p>Due to some reasons, I have to load two separate page header HTMLs in my page. One of them is a header for mobile view, and the other is for the desktop view. The rest of my page is responsive. My plan is to load both headers' HTMLs inside a JS that loads on page load and depending on page width populate the correct header's HTML inside my page, and hope the corresponding JS and CSS to load. I am doing this since the JS and CSS of the two header HTMLs are prone to clashing (and I can't tinker with these HTMLs), so I want only of them to load on a page load.</p>
  
  <p>The problem is in writing HTML in JSP inside this inline JS. I repeatedly get errors like "Uncaught SyntaxError: Unexpected token ILLEGAL".</p>
  
  <p><img src="https://i.stack.imgur.com/gVqlG.png" alt="enter image description here"></p>
  
  <p>My code in JSP looks like this:</p>
  
  <pre><code>            &lt;c:when test="${not empty hdrLoggedInHtml and not empty hdrLoggedInHtml_M}"&gt;
                  &lt;script type="text/javascript"&gt;
                      $(document).ready(function(){
                              if($(window).width()&gt;420)
                              {
                                  $("#desktopHeader").html('&lt;c:out value="${hdrLoggedInHtml}" escapeXml="false"/&gt;');
                                  $("#mobileHeader").html("");                                        
                              }else
                              {
                                  $("#mobileHeader").html('&lt;c:out value="${hdrLoggedInHtml_M}" escapeXml="false"/&gt;');
                                  $("#desktopHeader").html("");
                              }
  
                          });
                      });
                  &lt;/script&gt;
  
              &lt;/c:when&gt;
  </code></pre>
  
  <p>I tried using fn:escapeXml but that didn't work either. It seems to me that the new line after <code>&lt;html&gt;</code> inside the string is not getting output properly or some invisible character is coming somehow. 
  Please help. </p>