Created
August 26, 2010 12:14
-
-
Save makevoid/551292 to your computer and use it in GitHub Desktop.
debug javascript element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function debugg_multiple(elements, attrs) { | |
| if (attrs == undefined) | |
| attrs = []; | |
| string = ""; | |
| for (var i = elements.length - 1; i >= 0; i--){ | |
| string = string + debugg(elements[i], attrs) + "<br>"; | |
| }; | |
| return string; | |
| } | |
| function debugg(element, attrs) { | |
| if (attrs == undefined) | |
| attrs = []; | |
| string = ""; | |
| for (var i = attrs.length - 1; i >= 0; i--){ | |
| string = string + attrs[i]+": "+$(element).attr(attrs[i])+", "; | |
| }; | |
| return element+": { "+string+" }"; | |
| } | |
| // notes: | |
| // it requires jquery for the selector '$(element)' and the .attr("property") things, but this dependency can be easily removed | |
| // usage: | |
| // | |
| // // #konsole is a visible element in your html page to host the debug output | |
| // $("#konsole").html( | |
| // debugg_multiple(["img#foo", "img#bar"], ["src", "title"]) | |
| // ); | |
| // output: | |
| // | |
| // img#foo: { src: "foo.jpg", title: "What's a foo?" } | |
| // img#bar: { src: "bar.jpg", title: "A bar is a bar!" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment