Site icon Shyam Makwana

Debugging JavaScript with Firebug

debugging-with-firebug

debugging-with-firebug

To resolve the JavaScript error showing in Console and debug events bound to elements, you must have prior experience. This article is for those developers, who stuck when it comes to Debugging JavaScript conflicts or any error in Console.

Many thanks to Firebug team, who gives their essential time developing an immensely beautiful addon. New version of Firebug lets you find out and trace events bound to elements in the DOM.

See the screenshot (Events tab), in the HTML tab, inspect any Element, you will see 5 tabs with related information to that element on the right side. Style, Computed, Layout, DOM, Events. Name of tab says what it does. Here we will discuss on last Events tab.

Events Tab

Tracing Events

Inspect any element, the in HTML tab click on Events tab located in the right panel. It will show all the events bounded to that element.

There are different groups, like without group on top, then Listeners from Document, Other listeners for Document, Other listeners for Window.

Confused ? See Example below.

$(function(){
    // event listener direct to element
    $('.for-element-from-document').on('click', function(){
	console.log($(this).text());
    });

    // event listener from Document
    $(document).on('click','.for-element-from-document', function(){
	console.log($(this).text());
    });
});

As you can see in screenshot above, Now you know what they stands for. “Event directly to element” and “Event to Element from Document“.
In this example in second code technique used is called "Event delegation", I prefer using this every time if possible. Because its advantage is if DOM is modified and new elements are added, these events still triggers.

What Next ?

When you found event to element,

Playground

To play around, here below is a full example embedded, inspect

tag and look for events.

Exit mobile version