Simon_A
Simon_A

Reputation: 137

A list of properties for an HTML element

If I want to use javascript to change a property of something on a page I find it difficult to find the correct name to use.

For example if I have a button and I want to change the background colour I can use .style.background which I could find with a quick search on the net BUT what I can't seem to find is a comprehensive list of all the properties associated with that I could change.

Are there lists like this? Why cant I find them?

Upvotes: 0

Views: 1142

Answers (2)

user1726343
user1726343

Reputation:

You could use MDN to find the documentation for each DOM object type.

Here, for example, is a page describing the DOM interface for the form element, complete with properties and methods.

If you're going to use a console, I'd recommend logging the objects directly for an interactive view, instead of just logging a list of property names:

var div = document.createElement('div');

console.log(div);

Upvotes: 2

adeneo
adeneo

Reputation: 318182

var div = document.createElement('div')​;

​for (prop in div)​ {
    console.log(prop);
}​

This will list ALL the properties available on the div element in that particular browser.

FIDDLE

element.style.background will probably not be listed, as that is a style, not a property, but you can get all the styles by doing:.

var div = document.createElement('div');

console.log(div.style);

Upvotes: 2

Related Questions