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>
RangeTime:0.006311s
RangeMem:205.32 KB
返回顶部 留言