Change attribute type from submit to button?

How to change type attribute from submit to button using javascript or jQuery? I use an input element like <input type="submit" name="submitform"/> .

+4
source share
6 answers

Change the property of the native DOM node:

 document.getElementsByName("submitform")[0].type = "button"; 

Do it with jQuery:

 $("input[name='submitform']").prop("type", "button"); 

But remember that you cannot change input types in Internet Explorer 8 and below .

+16
source
 $('input').prop('type','button'); 
+4
source

You can use the setAttribute property of something like this in javascript

 document.getElementsByName("submitform").setAttribute('type', 'button'); 

for jQuery

 $('input[name="submitform"]').attr("type", "button"); 
+2
source

with jquery:

 $('input[name="submitform"]').attr('type','button') 
0
source

Using jQuery:

 $('input[name="submitform"]').attr('type', 'button'); 
0
source

For <input type="submit" name="submitform"/> ,

write jquery like:

 <script> $(document).ready(function(){ $('input[name="submitform"]').attr('type', 'button'); }); </script> 
0
source

All Articles