Clone a <form></form> tag and wrap it around existing content?

寵の児 提交于 2019-12-02 08:05:26
var $clone = $('#vCSS_mainform').clone().empty().attr('id', 'newId');
$('#vCSS_mainform').remove(); // only if you don't need it anymore.
$('#yourTable').wrap($clone);

note: if you remove the original form, you don't need to set a new id for the clone (no need of .attr('id', 'newId'))

This is relatively easy to achieve, really all you have to do, is use .clone(), .append() and .empty():

$('#vCSS_mainform').clone().appendTo($('body')).empty();

JS Fiddle demo.

Bear in mind, of course, that duplicate ids are invalid HTML.


Edited to complete the answer, to wrap the #accBox you could use:
$('#accBox').wrap($('#vCSS_mainform').clone().appendTo($('body')).empty());

JS Fiddle demo.

References:

$("#accBox").wrap($('#vCSS_mainform').clone().empty());

Fiddle demo

Infinity

Try someting like this.

function strip(htmlfullstring)
{
   var tmp = document.createElement("formid");
   tmp.innerHTML = html;
   return <form> + tmp.textContent||tmp.innerText+</form>;
}

if i understood your requirement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!