Constructor and Description |
---|
Elements() |
Elements(Collection<Element> elements) |
Elements(Element... elements) |
Elements(int initialCapacity) |
Elements(List<Element> elements) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(Element element) |
void |
add(int index,
Element element) |
boolean |
addAll(Collection<? extends Element> c) |
boolean |
addAll(int index,
Collection<? extends Element> c) |
Elements |
addClass(String className)
Add the class name to every matched element's
class attribute. |
Elements |
after(String html)
Insert the supplied HTML after each matched element's outer HTML.
|
Elements |
append(String html)
Add the supplied HTML to the end of each matched element's inner HTML.
|
String |
attr(String attributeKey)
Get an attribute value from the first matched element that has the attribute.
|
Elements |
attr(String attributeKey,
String attributeValue)
Set an attribute on all matched elements.
|
Elements |
before(String html)
Insert the supplied HTML before each matched element's outer HTML.
|
void |
clear() |
Elements |
clone()
Creates a deep copy of these elements.
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
Elements |
empty()
Empty (remove all child nodes from) each matched element.
|
Elements |
eq(int index)
Get the nth matched element as an Elements object.
|
boolean |
equals(Object o) |
Element |
first()
Get the first matched element.
|
List<FormElement> |
forms()
Get the
FormElement forms from the selected elements, if any. |
Element |
get(int index) |
boolean |
hasAttr(String attributeKey)
Checks if any of the matched elements have this attribute set.
|
boolean |
hasClass(String className)
Determine if any of the matched elements have this class name set in their
class attribute. |
int |
hashCode() |
boolean |
hasText() |
String |
html()
Get the combined inner HTML of all matched elements.
|
Elements |
html(String html)
Set the inner HTML of each matched element.
|
int |
indexOf(Object o) |
boolean |
is(String query)
Test if any of the matched elements match the supplied query.
|
boolean |
isEmpty() |
Iterator<Element> |
iterator() |
Element |
last()
Get the last matched element.
|
int |
lastIndexOf(Object o) |
ListIterator<Element> |
listIterator() |
ListIterator<Element> |
listIterator(int index) |
Elements |
not(String query)
Remove elements from this list that match the
Selector query. |
String |
outerHtml()
Get the combined outer HTML of all matched elements.
|
Elements |
parents()
Get all of the parents and ancestor elements of the matched elements.
|
Elements |
prepend(String html)
Add the supplied HTML to the start of each matched element's inner HTML.
|
Elements |
remove()
Remove each matched element from the DOM.
|
Element |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
Elements |
removeAttr(String attributeKey)
Remove an attribute from every matched element.
|
Elements |
removeClass(String className)
Remove the class name from every matched element's
class attribute, if present. |
boolean |
retainAll(Collection<?> c) |
Elements |
select(String query)
Find matching elements within this element list.
|
Element |
set(int index,
Element element) |
int |
size() |
List<Element> |
subList(int fromIndex,
int toIndex) |
Elements |
tagName(String tagName)
Update the tag name of each matched element.
|
String |
text()
Get the combined text of all the matched elements.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
Elements |
toggleClass(String className)
Toggle the class name on every matched element's
class attribute. |
String |
toString()
Get the combined outer HTML of all matched elements.
|
Elements |
traverse(NodeVisitor nodeVisitor)
Perform a depth-first traversal on each of the selected elements.
|
Elements |
unwrap()
Removes the matched elements from the DOM, and moves their children up into their parents.
|
String |
val()
Get the form element's value of the first matched element.
|
Elements |
val(String value)
Set the form element's value in each of the matched elements.
|
Elements |
wrap(String html)
Wrap the supplied HTML around each matched elements.
|
public Elements()
public Elements(int initialCapacity)
public Elements(Collection<Element> elements)
public Elements(Element... elements)
public Elements clone()
public String attr(String attributeKey)
attributeKey
- The attribute key.hasAttr(String)
public boolean hasAttr(String attributeKey)
attributeKey
- attribute keypublic Elements attr(String attributeKey, String attributeValue)
attributeKey
- attribute keyattributeValue
- attribute valuepublic Elements removeAttr(String attributeKey)
attributeKey
- The attribute to remove.public Elements addClass(String className)
class
attribute.className
- class name to addpublic Elements removeClass(String className)
class
attribute, if present.className
- class name to removepublic Elements toggleClass(String className)
class
attribute.className
- class name to add if missing, or remove if present, from every element.public boolean hasClass(String className)
class
attribute.className
- class name to check forpublic String val()
Element.val()
public Elements val(String value)
value
- The value to set into each matched elementpublic String text()
Note that it is possible to get repeats if the matched elements contain both parent elements and their own children, as the Element.text() method returns the combined text of a parent and all its children.
Element.text()
public boolean hasText()
public String html()
text()
,
outerHtml()
public String outerHtml()
public String toString()
outerHtml()
.public Elements tagName(String tagName)
<i>
to a <em>
, do
doc.select("i").tagName("em");
tagName
- the new tag nameElement.tagName(String)
public Elements html(String html)
html
- HTML to parse and set into each matched element.Element.html(String)
public Elements prepend(String html)
html
- HTML to add inside each element, before the existing HTMLElement.prepend(String)
public Elements append(String html)
html
- HTML to add inside each element, after the existing HTMLElement.append(String)
public Elements before(String html)
html
- HTML to insert before each elementElement.before(String)
public Elements after(String html)
html
- HTML to insert after each elementElement.after(String)
public Elements wrap(String html)
<p><b>This</b> is <b>Jsoup</b></p>
,
doc.select("b").wrap("<i></i>");
becomes <p><i><b>This</b></i> is <i><b>jsoup</b></i></p>
html
- HTML to wrap around each element, e.g. <div class="head"></div>
. Can be arbitrarily deep.Element.wrap(java.lang.String)
public Elements unwrap()
<div><font>One</font> <font><a href="/">Two</a></font></div>
doc.select("font").unwrap();
<div>One <a href="/">Two</a></div>
Node.unwrap()
public Elements empty()
E.g. HTML: <div><p>Hello <b>there</b></p> <p>now</p></div>
doc.select("p").empty();
HTML = <div><p></p> <p></p></div>
Element.empty()
,
remove()
public Elements remove()
E.g. HTML: <div><p>Hello</p> <p>there</p> <img /></div>
doc.select("p").remove();
HTML = <div> <img /></div>
Note that this method should not be used to clean user-submitted HTML; rather, use Cleaner
to clean HTML.
Element.empty()
,
empty()
public Elements select(String query)
query
- A Selector
querypublic Elements not(String query)
Selector
query.
E.g. HTML: <div class=logo>One</div> <div>Two</div>
Elements divs = doc.select("div").not("#logo");
Result: divs: [<div>Two</div>]
query
- the selector query whose results should be removed from these elementspublic Elements eq(int index)
See also get(int)
to retrieve an Element.
index
- the (zero-based) index of the element in the list to retainpublic boolean is(String query)
query
- A selectorpublic Elements parents()
public Element first()
null
if contents is empty.public Element last()
null
if contents is empty.public Elements traverse(NodeVisitor nodeVisitor)
nodeVisitor
- the visitor callbacks to perform on each nodepublic List<FormElement> forms()
FormElement
forms from the selected elements, if any.public int size()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(Element element)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<Element>
containsAll
in interface List<Element>
public boolean addAll(Collection<? extends Element> c)
public boolean addAll(int index, Collection<? extends Element> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public boolean equals(Object o)
public int hashCode()
public int lastIndexOf(Object o)
lastIndexOf
in interface List<Element>
public ListIterator<Element> listIterator()
listIterator
in interface List<Element>
public ListIterator<Element> listIterator(int index)
listIterator
in interface List<Element>
Copyright © 2009–2013 Jonathan Hedley. All rights reserved.