Since I have been listening to both the “Official jQuery Podcast” and the “yayQuery podcast” JavaScript and jQuery have been on my mind lately. It doesn’t hurt that some bugs I have fixed at work required mucking around in some jQuery. Someone from one of those podcasts referenced some things that you can do with the console in both IE and Firefox (with Firebug). Today I wanted to show some of the power of playing with the console.
I will be using IE 9 as my example browser today but you can do these things in Firefox and Google Chrome. So first lets open IE 9 and go to www.devdave.com. Press F12 to open up the developer tools of IE (documentation). You should notice an explorer bar, usually across the bottom of the screen.
Now that we know the class assigned to the div we can use that as a selector in jQuery. Two tabs over from the HTML tab there is a Console tab clicking that will open up a new part of the developer tools.
Since we have the correct selector we can type this to make the selected object slide up.
And then we can type this to make it slide down.
$(".tm-section").slideToggle('slow', function(){
alert("done");
});
}
toggle();
Pressing the Run Script button multiple times will cause the slide to toggle and an alert message to be displayed when its done.
As you can see this technique can really help in debugging or interrogating already running JavaScript. I have used this technique to debug asynchronous data paging issues, Google map marker issue.or just figuring out the correct selector syntax to select one or more objects in the DOM.