0

When I launch this in chrome, nothing appears on the page.

<!DOCTYPE html>
<head><title>test 4000</title><head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
document.writeln("test")
</script>
</body>
</html>
Guam
  • 1

1 Answers1

6

you are inserting code in a script tag that you are also using to load an external script (jQuery). you should either do the one or the other.

<script>
    document.writeln("test");
</script>

if you want both do:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    document.writeln("test");
</script>

the reference states:

If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

you do not need to include jQuery to use document.writeln()

dreamlab
  • 3,321
  • 20
  • 23
  • 1
    The "type=text/javascript" attribute is redundant, btw. You can safely take it away. – hugomg Aug 22 '14 at 21:36
  • 2
    The relevant reference is http://www.w3.org/TR/REC-html40/interact/scripts.html#edef-SCRIPT which says: “If the `src` has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.” – Jukka K. Korpela Aug 22 '14 at 21:39
  • @hugomg right. this is html5 only. thanks. – dreamlab Aug 22 '14 at 21:39
  • The reason that this behaviour is in the html5 standard is because it was already implemented by every browser out there. So in practice, ommiting the script type is also an "html4" feature. (This is also why the html5 doctype declaration is the way it is) – hugomg Aug 22 '14 at 21:42
  • html 4.01 [reference](http://www.w3.org/TR/html401/interact/scripts.html#adef-type-SCRIPT) says `The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute.` although browsers assumed it anyway. – dreamlab Aug 22 '14 at 21:44