jquery unwrap()

<p>.unwrap()Returns: jQuery</p><p>Description: Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.</p><p>version added: 1.4.unwrap()</p><p>This signature does not accept any arguments.</p><p>version added: 3.0.unwrap( [selector ] )</p><p>selector</p><p>Type: String</p><p>A selector to check the parent element against. If an element&#39;s parent does not match the selector, the element won&#39;t be unwrapped.</p><p>The .unwrap() method removes the element&#39;s parent and returns the unwrapped content. This is effectively the inverse of the .wrap() method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.</p><p>Example:</p><p>Wrap/unwrap a div around each of the paragraphs.</p><pre class="brush:html;toolbar:false">&lt;!doctypehtml&gt; &lt;html&gt; &lt;head&gt; &lt;metacharset=&quot;utf-8&quot;&gt; &lt;title&gt;unwrapdemo&lt;/title&gt; &lt;style&gt; div{ border:2pxsolidblue; } p{ background:yellow; margin:4px; } &lt;/style&gt; &lt;scriptsrc=&quot;https://code.jquery.com/jquery-1.10.2.js&quot;&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button&gt;wrap/unwrap&lt;/button&gt; &lt;p&gt;Hello&lt;/p&gt; &lt;p&gt;cruel&lt;/p&gt; &lt;p&gt;World&lt;/p&gt; &lt;script&gt; varpTags=$(&quot;p&quot;); $(&quot;button&quot;).click(function(){ if(pTags.parent().is(&quot;div&quot;)){ pTags.unwrap(); }else{ pTags.wrap(&quot;&lt;div&gt;&lt;/div&gt;&quot;); } }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</pre>




  1. 2021-12 (49)
  2. 2022-02 (1)
  3. 2022-03 (1)
  4. 2023-05 (4)
  5. 2023-06 (3)
  6. 2023-07 (6)
RangeMem:207.42 KB
返回顶部 留言