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

SyntaxError: expected expression, got '<', what does that mean?

  • Thread starter Thread starter nikel
  • Start date Start date
N

nikel

Guest
I have a a basic Html page which tries to use an external JS. The JS file tries to change the content of a paragraph defined in the HTML on a button click, but does not seem to work.

I see the following errors in console:


  1. SyntaxError: expected expression, got '<'


  2. ReferenceError: change is not defined

JSFiddle showing exact source?(except that <html> & <script> tags are removed as jsfiddle - http://jsfiddle.net/p9ko4yde/

HTML Code :

Code:
<h1> Numbers with external script:) </h1>
<p id="number">1</p>
<button type="button" onclick="change()">Toggle between 1 and 2</button>

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



</body>
</html>

JS Code :

Code:
<script type="text/javascript">
    function change(){
        var number = document.getElementById('number').innerHTML;
        if(number == '1'){
            document.getElementById('number').innerHTML='2';
        }
        else{
            document.getElementById('number').innerHTML='1';
        }
    }
</script>

File Structure is as below:enter image description here

<p>I have a a basic Html page which tries to use an external JS. The JS file tries to change the content of a paragraph defined in the HTML on a button click, but does not seem to work.</p>
<p>I see the following errors in console:</p>
<ol>
<li><p><code>SyntaxError: expected expression, got '<'</code></p>
</li>
<li><p><code>ReferenceError: change is not defined</code></p>
</li>
</ol>
<p>JSFiddle showing exact source?(except that <code><html></code> & <code><script></code> tags are removed as jsfiddle - <a href="http://jsfiddle.net/p9ko4yde/" rel="nofollow noreferrer">http://jsfiddle.net/p9ko4yde/</a></p>
<p>HTML Code :

</p>
<pre><code><h1> Numbers with external script:) </h1>
<p id="number">1</p>
<button type="button" onclick="change()">Toggle between 1 and 2</button>

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



</body>
</html>
</code></pre>
<p>JS Code :</p>
<pre><code><script type="text/javascript">
function change(){
var number = document.getElementById('number').innerHTML;
if(number == '1'){
document.getElementById('number').innerHTML='2';
}
else{
document.getElementById('number').innerHTML='1';
}
}
</script>
</code></pre>
<p>File Structure is as below:<a href="https://i.sstatic.net/NDAGa.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NDAGa.png" alt="enter image description here" /></a></p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top