从div父包装div

时间:2016-01-07 18:46:18

标签: jquery

我有这段代码

<div class="superdiv">
  <div></div>
  <div></div>
</div>

我想将所有.superdiv个子div包装成一个名为<div class="subdiv"></div>

的div

我该怎么做?

由于

2 个答案:

答案 0 :(得分:2)

您可以使用.wrapInner() method

private String _currentFileName;

public void SaveEntry(bool saveAs)
{
   if (saveAs || String.IsNullOrEmpty(_currentFileName))
   {
        saveFileDialog1.InitialDirectory = Application.StartupPath;
        saveFileDialog1.FileName = "FormData.bin";
        var result = saveFileDialog1.ShowDialog();

        // TODO: handle user cancellation
        _currentFileName = saveFileDialog1.FileName;
   }

   using (var writer = new StreamWriter(_currentFileName))
   {
       // TODO: do stuff with your writer
   }
}

您还可以在子元素上使用.wrapAll() method

$('.superdiv').wrapInner('<div class="subdiv"></div>');

答案 1 :(得分:0)

尝试以下

$(".superdiv > div").wrapAll("<div class='subdiv'/>");