Skip to content

Instantly share code, notes, and snippets.

@shellac
Last active December 17, 2015 15:59
Show Gist options
  • Save shellac/5635892 to your computer and use it in GitHub Desktop.
Save shellac/5635892 to your computer and use it in GitHub Desktop.
Issue with jsoup addClass -- leading empty class.
import java.util.Set;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class Jsoup {
public static void main(String... args) throws Exception {
Document html = Jsoup.parse("<html><body><p>Bye</p><p class=\"baz\">Hi</p></body></html>");
for (Element e: html.select("p")) {
e.addClass("foo");
e.addClass("bar");
System.out.println(e.attr("class"));
System.out.println(e.classNames());
}
System.out.println(html.toString());
System.out.println("".split("\\s+").length);
}
}
foo bar
[, foo, bar]
baz foo bar
[baz, foo, bar]
<html>
<head></head>
<body>
<p class=" foo bar">Bye</p>
<p class="baz foo bar">Hi</p>
</body>
</html>
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment