admin管理员组

文章数量:1332383

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">

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">
Share Improve this question edited Dec 12, 2012 at 8:40 Cerbrus 73k19 gold badges136 silver badges150 bronze badges asked Dec 12, 2012 at 7:51 Adesh singhAdesh singh 2,1339 gold badges24 silver badges36 bronze badges 3
  • Don't you think it should be: function my(){ document.getElementById("abc").innerHTML="hello"; } – Akhil Sekharan Commented Dec 12, 2012 at 7:53
  • you have to add function <script type="text/javascript"> function my() document.getElementById("abc").innerHTML="hello"; } </script> – user7282 Commented Dec 12, 2012 at 7:55
  • 1 check your script, have you forget to put { after function my() ? – vusan Commented Dec 12, 2012 at 9:58
Add a ment  | 

2 Answers 2

Reset to default 2

Missing the function keyword

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

        // Your code here
   }
</script>

please define your my function correctly like this:

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

本文标签: How to call javascript file in htmlStack Overflow