Element extends Node { public Element getElementById(String id) { Validate.notEmpty(id); Elements elements = Collector.collect(new Evaluator.Id(id), this); if (elements.size() > 0) return elements.get(0); else return null; } Element(Tag tag, String baseUri, Attributes attributes);  Element(Tag tag, String baseUri); @Override String nodeName(); String tagName(); Element tagName(String tagName); Tag tag(); boolean isBlock(); String id(); Node attr(String attributeKey, String attributeValue); Element attr(String attributeKey, boolean attributeValue); Map<String, String> dataset(); @Override final Node parent(); Elements parents(); Element child(int index); Elements children(); List<TextNode> textNodes(); List<DataNode> dataNodes(); Elements select(String cssQuery); Element appendChild(Node child); Element prependChild(Node child); Element insertChild(int index, Node child); Element insertChildren(int index, Collection<? extends Node> children); Element appendElement(String tagName); Element prependElement(String tagName); Element appendText(String text); Element prependText(String text); Element append(String html); Element prepend(String html); @Override Node before(String html); @Override Node before(Node node); @Override Node after(String html); @Override Node after(Node node); Element empty(); @Override Node wrap(String html); String cssSelector(); Elements siblingElements(); Element nextElementSibling(); Element previousElementSibling(); Element firstElementSibling(); int elementSiblingIndex(); Element lastElementSibling(); Elements getElementsByTag(String tagName); Element getElementById(String id); Elements getElementsByClass(String className); Elements getElementsByAttribute(String key); Elements getElementsByAttributeStarting(String keyPrefix); Elements getElementsByAttributeValue(String key, String value); Elements getElementsByAttributeValueNot(String key, String value); Elements getElementsByAttributeValueStarting(String key, String valuePrefix); Elements getElementsByAttributeValueEnding(String key, String valueSuffix); Elements getElementsByAttributeValueContaining(String key, String match); Elements getElementsByAttributeValueMatching(String key, Pattern pattern); Elements getElementsByAttributeValueMatching(String key, String regex); Elements getElementsByIndexLessThan(int index); Elements getElementsByIndexGreaterThan(int index); Elements getElementsByIndexEquals(int index); Elements getElementsContainingText(String searchText); Elements getElementsContainingOwnText(String searchText); Elements getElementsMatchingText(Pattern pattern); Elements getElementsMatchingText(String regex); Elements getElementsMatchingOwnText(Pattern pattern); Elements getElementsMatchingOwnText(String regex); Elements getAllElements(); String text(); String ownText(); Element text(String text); boolean hasText(); String data(); String className(); Set<String> classNames(); Element classNames(Set<String> classNames); boolean hasClass(String className); Element addClass(String className); Element removeClass(String className); Element toggleClass(String className); String val(); Element val(String value); String html(); @Override Appendable html(Appendable appendable); Element html(String html); String toString(); @Override Object clone();  }
@Test public void testGetElementById() { Document doc = Jsoup.parse(reference); Element div = doc.getElementById("div1"); assertEquals("div1", div.id()); assertNull(doc.getElementById("none")); Document doc2 = Jsoup.parse("<div id=1><div id=2><p>Hello <span id=2>world!</span></p></div></div>"); Element div2 = doc2.getElementById("2"); assertEquals("div", div2.tagName()); Element span = div2.child(0).getElementById("2"); assertEquals("span", span.tagName()); }