-1

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?

5
  • which version, as i am getting printed (starting, here), please try with preserve log checkbox Commented Jul 15, 2016 at 13:29
  • I'd expect to see a mixed content error somewhere since you are mixing HTTP and HTTPS. Commented Jul 15, 2016 at 13:29
  • 7
    text/javscript: check your spelling! Commented Jul 15, 2016 at 13:30
  • console displays TypeError: row.children is not a function Commented Jul 15, 2016 at 13:34
  • What trincot said. And after that you will get the error: "Refused to execute script from 'https://gist....test.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled." Commented Jul 15, 2016 at 13:40

4 Answers 4

3

There's two problems with what you're attempting to do:

  1. There's a typo on the line where you link to the Gist - should be text/javascript not text/javscript.

  2. Github doesn't allow you to hotlink to code/assets hosted on their website - essentially you can't use them as a CDN. Here's a blog post from them explaining this in more detail.

Sign up to request clarification or add additional context in comments.

Comments

2

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

-1

As I remember there is "onready" problem in this version of jQuery (I may be mistaken).

As for "text/javascript" it's unnecessary nowadays.

Comments

-1

Try to merge your two $(function(){}) into one, and remove these "returns" inside them. Like this:

    (function() {
      var hasChildren, rowsWithChildren;

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

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

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

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

    }).call(this);

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.