"When to use setAttribute vs .attribute= in JavaScript?"
A general rule is to use .attribute
and check if it works on the browser.
..If it works on the browser, you're good to go.
..If it doesn't, use .setAttribute(attribute, value)
instead of .attribute
for that attribute.
Rinse-repeat for all attributes.
Well, if you're lazy you can simply use .setAttribute
. That should work fine on most browsers. (Though browsers that support .attribute
can optimize it better than .setAttribute(attribute, value)
.)