What is the difference between setAttribute attribute and dot in Javascript?

Possible duplicate:
When to use setAttribute vs .attribute = in JavaScript?

Why do you sometimes set this attribute:

x.type = "submit"; 

and at other points:

x.setAttribute("type", "submit");

I always thought that no matter which direction, but I have a problem:

x.onClick = save;

but when I switch it to this, it works:

x.setAttribute("onClick", "save()");
+5
source share
1 answer

setAttributeonly works with DOM elements and reduces the attribute name on HTML elements. And you cannot use dot notation to assign values ​​to dynamic attribute names.

And also this:

setAttribute() , XUL, , . , . , elt.value elt.setAttribute('value', val).

+2

All Articles