How to change div into a button? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to change div into a button? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

How can I turn a DIV into an input button?

This works great for a checkbox to turn it into a type text:

$('#mycheckbox').get(0).type = 'text';

But that doesn’t work, nothing happens:

$('#mydiv').get(0).type = 'button'; //formatting

Answer

You can use replaceWith for div.

$("#mydiv").replaceWith("<input type='button' value='MyButton'>");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='mydiv'></div>
We are here to answer your question about How to change div into a button? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji