Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created August 26, 2010 12:14
Show Gist options
  • Select an option

  • Save makevoid/551292 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/551292 to your computer and use it in GitHub Desktop.
debug javascript element
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