Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: Add fieldset element between form

How to insert fieldset inform using jquery now I have this

<form action="" method="post">

all dynamic field generated with db and array

</form>

I want to add fieldset between form tag so code become

<form action="" method="post">
<fieldset>

all dynamic field generated with db and array

</fieldset>
</form>
like image 821
Code Lover Avatar asked Feb 17 '23 19:02

Code Lover


2 Answers

I'd recommend doing this server-side, but if you really need to use jQuery for this:

$('form').wrapInner('<fieldset />');

Fiddle

.wrapInner docs

like image 142
Fabrício Matté Avatar answered Mar 29 '23 16:03

Fabrício Matté


or you can do it like this:

    var newForm = "<fieldset>"+$('form').html()+"</fieldset>";
    $('form').html(newForm);
like image 25
Siamak Motlagh Avatar answered Mar 29 '23 16:03

Siamak Motlagh