11

Here is my code

String html = "<font>fsdfs<font>dfsdf</font>dasdasd</font>";
Document doc = Jsoup.parse(html);
Elements elements = doc.select("font");
for(Element element : elements)
{
element.replaceWith(new Element(Tag.valueOf("span"),"").html(element.html()));
}


System.out.println(doc.html());

I want to replace font tag and put span tag. In this it will replace first font tag but not second tag

0

1 Answer 1

33

You can replace the Tag like this too:

String html = "<font>fsdfs<font>dfsdf</font>dasdasd</font>";
Document doc = Jsoup.parse(html);
Elements elements = doc.select("font");


// rename all 'font'-tags to 'span'-tags, will also keep attributs etc.
elements.tagName("span");

System.out.println(doc.html());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.