user1167466
user1167466

Reputation: 333

Move all contrls inside form tag to div

This is the jQuery code that I am using to add the div to the page.

var div = jQuery(document.createElement('div'));
             div.attr('id', 'divFormWrapper');

             div.css({
                 "position": "absolute",
                 "top": 0,
                 "left": 0,
                 "width": "100%",
                 "height": "100%",
                 "overflow": "auto",
                 "-webkit-overflow-scrolling": "touch",
                 "background-color": "orange",
                 "border": "none",
                 "z-index": 0,
                 "display": "block"
             });

             jQuery('form').wrap(div);

It is adding the div tag before the form tag. I need it to add the div tag after the form tag.

 <div id="divFormWrapper" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; overflow-x: auto; overflow-y: auto; background-color: red; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; z-index: 0; display: block; ">
 <form name="Form1" method="post" id="Form1">

 controls.......
 </form>
 </div>

This is what I need it to do.

 <form name="Form1" method="post" id="Form1">
 <div id="divFormWrapper" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; overflow-x: auto; overflow-y: auto; background-color: red; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; z-index: 0; display: block; ">
 controls.......
 </div>
 </form>

Upvotes: 0

Views: 234

Answers (3)

j08691
j08691

Reputation: 207901

Instead of .wrap() use .wrapInner().

jsFiddle example.

Upvotes: 1

Glenit
Glenit

Reputation: 116

I'd modify it to use a more specific selector

$('#form1').children().wrapAll('<div id="divFormWrapper"/>`);

Upvotes: 0

James Montagne
James Montagne

Reputation: 78650

jQuery('form').children().wrapAll(div);

Upvotes: 0

Related Questions