title: If PHP echo code returns a value then run script. Else nothing
body: <p>I have the following code which returns the result I require inside of a tab. But because the JavaScript is in the same file it shows a blank tab when there is no data to show. I remove the JavaScript and the tab disappears. How can I run the JavaScript only if data is present so the tab will disappear? Or can I call it from another file?</p>
  
  <pre><code>&lt;?php echo $block-&gt;escapeHtml($block-&gt;getProduct()-&gt;getData($this-&gt;getCode()));
  ?&gt;
  &lt;script type="text/JavaScript"&gt;
      var commareplace = document.querySelectorAll("div &gt; #bikefitment");
      for (var i = 0; i &lt; commareplace.length; i++) {
          commareplace[i].innerHTML = commareplace[i].innerHTML.replace(/,/g, "&lt;br /&gt;");
      }
  &lt;/script&gt;
  </code></pre>