OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

External .JS file doesn't render HTML inside web page [duplicate]

  • Thread starter Thread starter valeclee
  • Start date Start date
V

valeclee

Guest
I'm trying to get my script.js to render HTML inside my page. But it's not doing it.

I get Uncaught SyntaxError: expected expression, got '<' in the console


Code:
document.body.appendChild(document.createElement('div'))
  .textContent = 'Hello!!';

Code:
<h1>Welcome to my website</h1>

<script src="script.js"></script>

<p>I'm trying to get my script.js to render HTML inside my page. But it's not doing it.</p>
<p>I get <code>Uncaught SyntaxError: expected expression, got '<'</code> in the console</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>document.body.appendChild(document.createElement('div'))
.textContent = 'Hello!!';</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><h1>Welcome to my website</h1>

<script src="script.js"></script></code></pre>
</div>
</div>
</p>
 

Latest posts

Top