I’ve been having a lovely day at work, fiddling with jQuery. I started to come up with some really gnarly selector chains though, and I wondered what nodes they were actually addressing.
So, I wrote a tiny jQuery extension that logs the current jQuery selection to the firebug console.
jQuery.fn.log = function (msg) { console.log("%s: %o", msg, this); return this; };
Now, I can just stuff a call to .log() in the middle of what I’m doing to see what I’m currently addressing. e.g.
$(root).find('li.source > input:checkbox').log("sources to uncheck").removeAttr("checked");
The nice thing about logging to firebug is that each node becomes clickable in the console, so you can immediately see the context.
Comments 17
genius!
Posted 27 Sep 2007 at 8:54 am ¶Clever, it’ll come in very handy.
Posted 28 Sep 2007 at 10:10 pm ¶I’ll repeat Mark: genius!
Posted 19 Oct 2007 at 3:26 pm ¶Brilliant ! Thanks for sharing it
Posted 19 Oct 2007 at 4:44 pm ¶Cool!
Posted 19 Oct 2007 at 5:53 pm ¶Awesome!
I would just add:
if( console )
inside the function. for cleanliness reasons…i might be testing on different browsers at the same time.
Posted 19 Oct 2007 at 6:08 pm ¶Great Resource, Thank you for creating this.
I agree on the if( console ) issue, I would also recommend a handy grep script to remove the .log commands from the script before production.
Posted 19 Oct 2007 at 7:24 pm ¶you could always include firebug lite in your pages and then no need for unnecessary if statements – the script is cached after first time
cool idea!
Posted 19 Oct 2007 at 7:55 pm ¶Great, thank you!
Posted 19 Oct 2007 at 10:33 pm ¶Very cool! This will come in handy for sure.
Posted 19 Oct 2007 at 11:17 pm ¶any demo?
Posted 20 Oct 2007 at 2:45 am ¶any demo available?
Posted 20 Oct 2007 at 2:46 am ¶Sounds good, a demo would help
Posted 20 Oct 2007 at 6:19 am ¶Looks like you need a Captcha
Posted 20 Oct 2007 at 1:45 pm ¶Hi,
That is a great jQuery plugin, which is also working with Companion.JS (http://www.my-debugbar.com/wiki/CompanionJS/HomePage), so you can also log under IE !
No info about node yet
but maybe in a future release.
JFR
Posted 20 Oct 2007 at 4:26 pm ¶http://www.debugbar.com
Hello Dominic,
I tried to improve the plugin with some conditionals, take a look at it
http://pastemonkey.org/paste/471a49a0-fc54-4ca8-b8e7-5411404fdb0d
Posted 20 Oct 2007 at 7:33 pm ¶cool! thanks for sharing
Posted 02 Sep 2008 at 4:08 pm ¶Post a Comment