You need to modify the HTML of an element.html
Use the HTML setter methods in Element
:java
Element div = doc.select("div").first(); // <div></div> div.html("<p>lorem ipsum</p>"); // <div><p>lorem ipsum</p></div> div.prepend("<p>First</p>"); div.append("<p>Last</p>"); // now: <div><p>First</p><p>lorem ipsum</p><p>Last</p></div> Element span = doc.select("span").first(); // <span>One</span> span.wrap("<li><a href='http://example.com/'></a></li>"); // now: <li><a href="http://example.com"><span>One</span></a></li>
Element.html(String html)
clears any existing inner HTML in an element, and replaces it with parsed HTML.node
Element.prepend(String first)
and Element.append(String last)
add HTML to the start or end of an element's inner HTML, respectivelyapi
Element.wrap(String around)
wraps HTML around the outer HTML of an element.app
You can also use the Element.prependElement(String tag)
andElement.appendElement(String tag)
methods to create new elements and insert them into the document flow as a child element.spa