Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JS basics – how to separate javascript into a separate file

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #198625
    amyK
    Participant

    I’m just getting started in making the leap from javascript hack to active learner. Case in point – here’s an old project with javascript written directly into html document. How do I separate this out into its own file? I know how to link from html but I don’t know how to structure the js document.

    Any help appreciated!

    http://amykalisher.com/fc/assign3-2.html

    #198629
    Senff
    Participant

    What do you mean, you don’t know how to structure the JS content? In this case you may just want to copy the JS and paste it all into a new document called something like myScripts.js, or that’s not good?

    #198638
    Paulie_D
    Member

    There’s a shipload of js events inlined to every image.

    Frankly, it would probably better to rewrite the thing completely.

    #198643
    amyK
    Participant

    Thanks for your comments. Paulie, I think you see what I’m getting at. When you say it would be better to rewrite, do you have an idea about how to approach this? I appreciate your guidance, thanks.

    #198648
    Paulie_D
    Member

    Well I don’t know how it was written in the first place but js (and js libraries) have come along way.

    Start from the basics and try not to repeat code whenever possible.

    #198658
    Shikkediel
    Participant

    I tried to give an example (since I recommended the separation before) but the code got rejected by the forum. Might be worth having a look at document.getElementById('id') for outsourcing the script that’s inside the image tags.

    #198660
    Paulie_D
    Member

    The forum really doesn’t like Javascript.

    Codepen would be better.

    #198661
    Shikkediel
    Participant

    No doubt, it was only two lines of code though (down to one it worked).

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.