Recently I was working on a piece of code where the requirement was to create buttons dynamically on click of another link/button. The code was:

var button1=document.createElement(’INPUT’);
button1.name =’button1_name’;
button1.setAttribute(”type”,”button”);
button1.setAttribute(”id”,”button1_id”);
button1.setAttribute(”value”,”Submit”);

The above code was working perfect in Firefox. However, in IE 6, this code did not create a button. It simply didn’t work! While trying to find a solution, I came across a link that said while creating dynamic buttons through Javascript, the ‘type’ attribute can’t be set dynamically using setAttribute() in IE 6. What needed in IE 6 was:

var button1=document.createElement(’<input type=”button” name=”button1_name” />’);

The above code will also work for Firefox, thus to make it cross-browser, had to hard-code the tag as written above.

Related posts:

  1. ‘Object Expected’ error in IE 6
  2. “Unknown runtime error” in IE8 while using ajax
  3. Show table row (tr) using css
  4. image setAttribute() does not work in IE 8
  5. Apache FOP - Formatting Objects Processor