/** * Shortcut for <code>context.find(css)</code>. */ public static Jerry $(final String cssSelector, final Jerry context) { return context.find(cssSelector); }
/** * @see #find(String) */ public Jerry $(final String cssSelector) { return find(cssSelector); }
/** * Adds elements to the set of matched elements. */ public Jerry add(final String selector) { return new Jerry(this, nodes, root().find(selector).nodes); }
/** * Removes elements from the set of matched elements. */ public Jerry not(final String cssSelector) { Node[] notNodes = root().find(cssSelector).nodes; List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { if (!ArraysUtil.contains(notNodes, node)) { result.add(node); } } } return new Jerry(this, result); }
@Test void testEmptyClassAttribute() { Jerry doc = Jerry.jerry("<div class></div>"); try { doc.find(".foo"); } catch(Exception e) { fail(e.toString()); } }
@Test void testIterator1() { Jerry doc = Jerry.jerry().parse("<div id='one' class='foo'>one</div><div id='two' class='foo'>two</div>"); Iterator<Jerry> iterator = doc.find(".foo").iterator(); String result = ""; while (iterator.hasNext()) { Jerry j = iterator.next(); result += j.attr("id"); } assertEquals("onetwo", result); }
@Test void testIterator2() { Jerry doc = Jerry.jerry().parse("<div id='one' class='foo'>one</div><div id='two' class='foo'>two</div>"); Iterator<Jerry> iterator = doc.find(".notfound").iterator(); String result = ""; while (iterator.hasNext()) { Jerry j = iterator.next(); result += j.attr("id"); } assertEquals("", result); }
Jerry form = find(formCssSelector);
@Test void testEnd() { String html = readFile("end.html"); String htmlOK = readFile("end-ok.html"); Jerry $ = jerry(html).$("p").find("span").end().css("border", "2px red solid"); assertEquals(htmlOK, actualHtml($)); }
@Test void testPseudoEq2() { String html = readFile("pseudoEq2.html"); String htmlOK = readFile("pseudoEq2-ok.html"); Jerry doc = jerry(html); doc.$("ul.nav li:eq(1)").css("backgroundColor", "#ff0"); doc.$("ul.nav").each(($this, index) -> { $this.find("li:eq(1)").css("fontStyle", "italic"); return true; }); doc.$("ul.nav li:nth-child(2)").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testHtmlAll() { Jerry j = Jerry.jerry("<div><span>1</span></div><div><span>2</span></div>"); assertEquals(j.htmlAll(true), j.htmlAll(false)); j = j.$("div"); assertEquals("<span>1</span>", j.html()); assertEquals("<span>1</span><span>2</span>", j.htmlAll(false)); assertEquals("<div><span>1</span></div><div><span>2</span></div>", j.htmlAll(true)); Jerry j2 = j.find("span"); assertEquals(2, j2.length()); assertEquals("12", j2.text()); assertEquals("1", j2.html()); assertEquals("12", j2.htmlAll(false)); assertEquals("<span>1</span><span>2</span>", j2.htmlAll(true)); }
/** * @see #find(String) */ public Jerry $(final String cssSelector) { return find(cssSelector); }
/** * Shortcut for <code>context.find(css)</code>. */ public static Jerry $(final String cssSelector, final Jerry context) { return context.find(cssSelector); }
/** * Shortcut for <code>context.find(css)</code>. */ public static Jerry $(String cssSelector, Jerry context) { return context.find(cssSelector); }
/** * @see #find(String) */ public Jerry $(String cssSelector) { return find(cssSelector); }
/** * Adds elements to the set of matched elements. */ public Jerry add(final String selector) { return new Jerry(this, nodes, root().find(selector).nodes); }
/** * Adds elements to the set of matched elements. */ public Jerry add(String selector) { return new Jerry(this, nodes, root().find(selector).nodes); }
/** * Removes elements from the set of matched elements. */ public Jerry not(String cssSelector) { Node[] notNodes = root().find(cssSelector).nodes; List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { if (ArraysUtil.contains(notNodes, node) == false) { result.add(node); } } return new Jerry(this, result); }
/** * Removes elements from the set of matched elements. */ public Jerry not(final String cssSelector) { Node[] notNodes = root().find(cssSelector).nodes; List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { if (!ArraysUtil.contains(notNodes, node)) { result.add(node); } } } return new Jerry(this, result); }