src/main/java/org/jsoup/nodes/Element.java
/**
     Wrap the supplied HTML around this element.
     @param html HTML to wrap around this element, e.g. {@code <div class="head"></div>}. Can be arbitralily deep.
     @return this element, for chaining.
     */
Wrap the supplied HTML around this element.
Wrap the supplied HTML around this element .
public Element wrap(String html) {
        Validate.notEmpty(html);
        Element wrapBody = Parser.parseBodyFragment(html, baseUri).body();
        Elements wrapChildren = wrapBody.children();
        Element wrap = wrapChildren.first();
        if (wrap == null) 
            return null;
        Element deepest = getDeepChild(wrap);
        parentNode.replaceChild(this, wrap);
        deepest.addChild(this);
        if (wrapChildren.size() > 1) {
            for (int i = 1; i < wrapChildren.size(); i++) { 
                Element remainder = wrapChildren.get(i);
                remainder.parentNode.removeChild(remainder);
                wrap.appendChild(remainder);
            }
        }
        return this;
    }
public Element wrap ( String html ) { Validate . notEmpty ( html ) ; Element wrapBody = Parser . parseBodyFragment ( html , baseUri ) . body ( ) ; Elements wrapChildren = wrapBody . children ( ) ; Element wrap = wrapChildren . first ( ) ; if ( wrap == null ) return null ; Element deepest = getDeepChild ( wrap ) ; parentNode . replaceChild ( this , wrap ) ; deepest . addChild ( this ) ; if ( wrapChildren . size ( ) > 1 ) { for ( int i = 1 ; i < wrapChildren . size ( ) ; i ++ ) { Element remainder = wrapChildren . get ( i ) ; remainder . parentNode . removeChild ( remainder ) ; wrap . appendChild ( remainder ) ; } } return this ; }
Wrap the supplied HTML around this element.
Wrap the supplied HTML around this element .
// nothing to wrap with; noop // remainder (unbalananced wrap, like <div></div><p></p> -- The <p> is remainder // skip first