/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { if (nodes.length == 0) { return this; } if (text == null) { text = StringPool.EMPTY; } for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(node.getOwnerDocument(), text); node.addChild(textNode); } return this; }
@Test void testHtmlNodesOwner() { Jerry doc = Jerry.jerry().parse("<div>1<div id='x'>2</div>3</div>"); doc.$("#x").html("<span>wow</span>"); assertEquals("<div>1<div id=\"x\"><span>wow</span></div>3</div>", doc.html()); Element divx = doc.get(0).getChildElement(0).getChildElement(0); assertSame(doc.get(0), divx.getOwnerDocument()); assertEquals("span", divx.getChildElement(0).getNodeName()); assertSame(doc.get(0), divx.getChildElement(0).getOwnerDocument()); assertSame(doc.get(0), divx.getChildElement(0).getChild(0).getOwnerDocument()); }
/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(node.getOwnerDocument(), text); node.addChild(textNode); } return this; }
/** * Sets the content of each element in the set of matched elements to the specified text. */ public Jerry text(String text) { if (nodes.length == 0) { return this; } if (text == null) { text = StringPool.EMPTY; } for (Node node : nodes) { node.removeAllChilds(); Text textNode = new Text(node.getOwnerDocument(), text); node.addChild(textNode); } return this; }