Browsers bail on DOM button.type="button"

The following will throw an exception:

var button=document.createElement("button"); button.type="button";

The only workaround for dynamically creating <button type="button"> seems to be to convert the button HTML to a string and append it to innerHTML.

Test page Workaround is included
Reported by: Garret Wilson.

Explorer 5-6 Windows, Explorer 7, Explorer Mac, Opera | Reported on 10 October 2005.

This site is no longer maintained. I’m sorry, but it’s just too much work for too little return. You can continue to browse old bug reports, though.




Search reports by browser:

Atom RSS

Comments

(Add your own)

1 Posted by Alu Jones on 11 October 2005 | Permalink

Use:
button.setAttribute('type', 'button');

2 Posted by SG_01 on 23 August 2006 | Permalink

The default type of button is button.

Try:
javascript: var button = document.createElement("button"); alert(button.type);

3 Posted by mephinet on 31 January 2007 | Permalink

> The default type of button is button.

not true on firefox 2.0 and opera 9.10, the default is "submit" there.