Console.log not working at all

后端 未结 13 713
故里飘歌
故里飘歌 2020-12-29 02:13

A bunch of code isn\'t working and I\'m trying to identify where the problem lies but console.log() isn\'t logging any results in Chrome Dev tools, am I doing i

13条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 02:29

    Sounds like you've either hidden JavaScript logs or specified that you only want to see Errors or Warnings. Open Chrome's Developer Tools and go to the Console tab. At the bottom you want to ensure that JavaScript is ticked and also ensure that you have "All", "Logs" or "Debug" selected.

    Example Screenshot

    In the image above I have JavaScript, Network, Logging, CSS and Other ticked and "All" selected.


    Another potential problem could be that your $(window).scroll() function isn't wrapped within a .ready() function (as documented here):

    $(document).ready(function() {
        $(window).scroll(function() {
            ...
        });
    });
    

    When pasting your code into JSFiddle and giving some dummy content, your code works perfectly fine: JSFiddle demo.


    Edit:

    The question was edited. The new code given throws two errors:

    Uncaught ReferenceError: fitHeight is not defined Uncaught TypeError: Cannot read property 'addEventListener' of null

    Because of this, the code stops execution prior to reaching any console.log call.

提交回复
热议问题