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 heavily relies on bug reports created by its readers. Anyone can report a bug and be published.




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.

Post a comment

Commenting guidelines:

  1. When quoting specs, articles or your own research, please include a URL of the document.
  2. Test your stuff. When reporting browser behaviour, make sure that your report is correct.

Yes