Home > Web Front-end > HTML Tutorial > [Jsoup Learning Etiquette] Set the HTML content of an element_html/css_WEB-ITnose

[Jsoup Learning Etiquette] Set the HTML content of an element_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:48:26
Original
1028 people have browsed it

Problem

You need the HTML content in an element

Method

You can use the HTML setting method in Element as follows:

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前添加html内容div.append("<p>Last</p>");//在div之后添加html内容// 添完后的结果: <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>");// 添完后的结果: <li><a href="http://example.com"><span>One</span></a></li>
Copy after login

Description

  • Element.html(String html) This method will first clear the HTML content in the element and then replace it with the incoming HTML.
  • Element.prepend(String first) and Element.append(String last) methods are used to add HTML content before and after the HTML inside the element respectively
  • Element.wrap(String around) Wrap an external HTML content around the element.
  • See

    You can view the Element.prependElement(String tag) and Element.appendElement(String tag) methods in the API reference document to create new elements and insert them as child elements of the document.

    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template