How to ignore certain script files / lines when debugging?

前端 未结 6 1280
南方客
南方客 2020-12-31 11:56

I\'m trying to debug some JavaScript, I want to find out what code gets executed when I hover over a certain div element (I\'ve got no idea which bit of code, because there\

6条回答
  •  被撕碎了的回忆
    2020-12-31 12:32

    If you're pretty sure it's a jQuery event handler you can try to poke around with the jQuery events. This will overwrite all the click handlers (replace with the type you're interested in) and log out something before each event handler is called:

    var elem = document.body; // replace with your div
    // wrap all click events:
    $.each($._data(elem).events.click, function(i, v) { 
        var h = v.handler; 
        v.handler = function() {
          // or use 'alert' or something here if no Dev Tools
          console.log('calling event: '+ i);
          console.log('event handler src: '+ h.toString()); 
          h.apply(h, arguments); 
        };
    })
    

    Then try calling the event type directly through jQuery to rule out that type:

    $('#your_div').click()
    

提交回复
热议问题