You need to modify the text content of a HTML document.html
Use the text setter methods of Element
:java
Element div = doc.select("div").first(); // <div></div> div.text("five > four"); // <div>five > four</div> div.prepend("First "); div.append(" Last"); // now: <div>First five > four Last</div>
The text setter methods mirror the HTML setter methods:node
Element.text(String text)
clears any existing inner HTML in an element, and replaces it with the supplied text.api
Element.prepend(String first)
and Element.append(String last)
add text nodes to the start or end of an element's inner HTML, respectivelyapp
The text should be supplied unencoded: characters like <
, >
etc will be treated as literals, not HTML.spa