/    Sign up×
Community /Pin to ProfileBookmark

Where to put JS code?

I am a self learner of JS, but looking at many sites got confused where to put JS code? Should it be within the <head> tags, <body> tags or in-between? I saw web-sites which used all placements…

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@VladdyMay 20.2005 — Looking at the websites is about the worst way to learn - 99.9% of coding you find is incorrect.

Rule #1 for self learners (and the rest as well): [b]"When in doubt, [URL=http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html]RTFM[/URL]"[/b]
Copy linkTweet thisAlerts:
@TheBearMayMay 20.2005 — Most commonly it is placed within the <head> tags, there are times however where you may want to place it in the <body> (generally when you want to make sure an HTML element has been instantiated before execution of the JS).
×

Success!

Help @Vic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...