Kevin Meredith Kevin Meredith - 4 months ago 7
HTML Question

Javascript Not Running in HTML

Given the following:

HTML



<!DOCTYPE html>
<html>

<head>
<title>test</title>
</head>

<body>

<table>
<tr class='foo'><td>one</td></tr>
<tr class='foo'><td>two</td></tr>
<tr class='foo'><td>three</td></tr>
</table>

<script type="text/javascript" src="http://underscorejs.org/underscore.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script type="text/javscript" src="https://gist.githubusercontent.com/anonymous/d25940992da18e05f3f2d50889f6a4c2/raw/f013565c33d17abb33a4f5ad7717aae090873516/test.js"></script>
</body>

</html>


JS



// Generated by CoffeeScript 1.10.0
(function() {
var hasChildren, rowsWithChildren;

$(function() {
return console.log('starting');
});

$(function() {
var filtered, rows;
console.log('here');
rows = $('tr');
filtered = rowsWithChildren(rows);
return console.log(filtered);
});

rowsWithChildren = function(rows) {
return _.filter(rows, function(r) {
return hasChildren(r);
});
};

hasChildren = function(row) {
return row.children().length === 1;
};

}).call(this);


When I open that HTML page in my Chrome Browser, I see the table on the screen. But, I don't see any
console.log ...
statements in the output of the Developer Tools
Console
.

Also, when I look at Dev Tool's
Sources
, I don't see the JS from
gist.github.com...
.

What's wrong with this HTML?

Answer

The third script element has a wrong type value. With a wrong value, the loaded file will not be interpreted as JavaScript.

So change:

<script type="text/javscript"  ...

to:

<script type="text/javascript"  ...
Comments