Unable to change <button> "type" using Javascript

On Chromium 7.0.517.44 (64615) Ubuntu 10.10, I seem to be unable to change the type attribute of the <button> element:

 > blah = document.createElement("button") <button>​</button>​ > blah.type "submit" > blah.type = "button" "button" > blah.type "submit" 

reference


On Firefox 3.6.12 and Opera 10.63, it works fine:

 >>> blah = document.createElement("button") <button> >>> blah.type "submit" >>> blah.type = "button" "button" >>> blah.type "button" 
+4
source share
3 answers

Use setAttribute .

 blah.setAttribute('type', 'button'); 
+12
source

Changing the type attribute on any of the incoming families usually doesn't work (I know that it doesn't work on input ).

What you can do is clone the element, replace the type attribute, and the HTML is serialized, and then add it after. Then delete the original.

+1
source

==================================================== ======================

JavaScript:

  function submit_button(){ var btn=document.getElementById(button_id'); btn.setAttribute('type', 'submit'); } 

==================================================== ======================

Jquery:

  function submit_button(){ $('#' + button_id).prop('type', 'submit'); } 

==================================================== ======================

he works here .....

+1
source

All Articles