Created
May 27, 2025 15:28
-
-
Save documentprocessing/bb4aa6942d5fb64ce43db161f8621ab9 to your computer and use it in GitHub Desktop.
Modify HTML of an Element in Java with jsoup API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment