0

I ve just begin with Jquery, i ve import the jquery file src="http://code.jquery.com/jquery-latest.min.js in my html file. I want to import also other functions that i ve created in the same file. How is this possible to import several js files? For example i want to seperate ready from html file to a new js file:

enter <!DOCTYPE html>
      <html>
      <head>

      <link rel="stylesheet" type="text/css" href="site.css" />
      <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">                                          
      </script>

      </head>

      <body>

   <h1><b> TWEET PEAK  </b></h1>
   <a class="button_example button_about" href=" menu.html">    </a>

   <img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/elevator.png"/> 

    <script> 
        $(document).ready(function(){

        $('img').animate({top:'+=100px'},1000);
    });
</script>

    </body>
    </html>here
3
  • Just add another script tag and reference any filename you want, then create that file and add your script into it (without the script tags) :) Commented Oct 3, 2013 at 12:32
  • something like that?? <script src = script.js><img src="http://... .png </script> Commented Oct 3, 2013 at 12:34
  • See the answer by Kai below :) Commented Oct 3, 2013 at 12:35

1 Answer 1

3

You'll want to put your JavaScript code in a separate file and link to it using another script tag. For example, if you put your JavaScript in a file called "mycode.js" you would link to it like this:

<script type="text/javascript" src="mycode.js"></script>

In this example mycode.js would contain:

$(document).ready(function(){

    $('img').animate({top:'+=100px'},1000);
});

Edit, to be more clear:

Here is how I see your example code looking:

  <link rel="stylesheet" type="text/css" href="site.css" />
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">                                          
  </script>
  <script type="text/javascript" src="mycode.js"></script>
  <style> img { position: relative; } </style>
  </head>

  <body>

<h1><b> TWEET PEAK  </b></h1>
<a class="button_example button_about" href=" menu.html">    </a>

<img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/elevator.png"/> 


</body>
</html>
Sign up to request clarification or add additional context in comments.

6 Comments

Note - the script tag needs to go after the one that's already in the html file so that jQuery gets loaded first :)
Ok so then my problem is animate since it doesnt function properly.
You don't want to put your img tag inside the script tags. You should place it between the "<body></body>" tags in your HTML.
Yeah it is quite logical, but for some reason the animation doesnt function.
By the way, your problem with the animation is that your image should be positioned relatively. In otherwords, add this style: <style>img { position: relative; } </style>
|

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.