wilsonpage
wilsonpage

Reputation: 17600

How do you log all an element's properties?

I want to see in the console all the available properties on an html element.

console.log(myEl); 

Just logs the html structure of the object.

Upvotes: 0

Views: 194

Answers (3)

harpo
harpo

Reputation: 43188

var a = document.getElementsByTagName('a')[0];
for (var key in a)
    console.log(key, a[key]);

Upvotes: 0

Wolfgang Kuehn
Wolfgang Kuehn

Reputation: 12926

See http://getfirebug.com/logging: console.dir(object)

Upvotes: 4

ComFreek
ComFreek

Reputation: 29434

var str = "";
for ( var attr in myEl )
{
  if (typeof myEl[attr]!="function")
    str += attr + ":" + myEl[attr] + "\n";
}
console.log(str);

Upvotes: 0

Related Questions