[Solved] Why can’t I put JS code between CODE?


You can specify the src attribute or include the code as the content of the script tag. As you’ve discovered, you can not do both simultaneously.

Here’s what Mozilla Developer Network has to say about the src attribute (emphasis at the end added):

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

You can also come to the same conclusion by carefully reading the W3C Recommendation at http://www.w3.org/TR/html5/scripting-1.html but I don’t see it stated so concisely. (Correction welcome! Maybe I’m just not seeing it.) You have to follow along the steps to preparing a script.

0

solved Why can’t I put JS code between ?