Console.log not working at all

后端 未结 13 648
故里飘歌
故里飘歌 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:40

    You may have used the filter function in the console which will hide anything that doesn't match your query. Remove the query and your messages will display.

    0 讨论(0)
  • 2020-12-29 02:43

    As a complete new at javascript, I just had the same problem on my side here. The mistake I did, was that I used:

    <script type="text.javascript">
      console.log("bla bla bla");
    </script>
    

    instead of:

    <script>
      console.log("bla bla bla");
    </script>
    

    using the

    type="text.javascript"

    had the result of not producing the log in the console.

    0 讨论(0)
  • 2020-12-29 02:44

    Just you need to select right option to show the log messages from the option provided in left side under the console tab. You can refer the screen shot.

    0 讨论(0)
  • 2020-12-29 02:46

    I feel a bit stupid on this but let this be a lesson to everyone...Make sure you target the right selector!

    Basically the console wasn't logging anything because this particular code snippet was attempting to grab the scrolling area of my window, when in fact my code was setup differently to scroll an entire DIV instead. As soon as I changed:

    $(window).scroll(function() {
    

    to this:

    $('#scroller').scroll(function() {
    

    The console started logging the correct messages.

    0 讨论(0)
  • 2020-12-29 02:46

    It was because I had turned off "Logs" in the list of boxes earlier.

    0 讨论(0)
  • 2020-12-29 02:54

    Consider a more pragmatic approach to the question of "doing it correctly".

    console.log("about to bind scroll fx");
    
    $(window).scroll(function() {
    
           console.log("scroll bound, loop through div's");
    
           $('div').each(function(){
    

    If both of those logs output correctly, then its likely the problem exists in your var declaration. To debug that, consider breaking it out into several lines:

    var id='#'+$(this).attr('id');
    
    console.log(id);
    
    var off=$(id).offset().top;
    var hei=$(id).height();
    var winscroll=$(window).scrollTop();
    var dif=hei+off-($(window).height());
    

    By doing this, at least during debugging, you may find that the var id is undefined, causing errors throughout the rest of the code. Is it possible some of your div tags do not have id's?

    0 讨论(0)
提交回复
热议问题