3

I am trying to call innerHtml in JavaScript its working in the same file but not in the separate JavaScript JS file. my working code is

<script type="text/javascript">
   function my()
    document.getElementById("abc").innerHTML="hello";
    } 
    </script>
<div id="abc" onmouseover ="my()"> hi hw ru  </div>

But if I invoke this method in separate JavaScript file its not working even I am giving the source path of the JavaScript file like

<script type="text/javascript" src="js/framemrq.js">
3
  • Don't you think it should be: function my(){ document.getElementById("abc").innerHTML="hello"; } Commented Dec 12, 2012 at 7:53
  • you have to add function <script type="text/javascript"> function my() document.getElementById("abc").innerHTML="hello"; } </script> Commented Dec 12, 2012 at 7:55
  • 1
    check your script, have you forget to put { after function my() ? Commented Dec 12, 2012 at 9:58

2 Answers 2

2

Missing the function keyword

<script type="text/javascript">
  function my(){

        // Your code here
   }
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

please define your my function correctly like this:

function my() {
    document.getElementById("abc").innerHTML="hello";
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.