Select element but deselect specified child of element

Trevor Wood

Just curious if this is possible in jsoup

Select an element and it's text but deselect a specified child.

<div>
  <p><strong>Location: </strong> Earth</p>
</div>

Is it possible to return just Earth?

Edit: Also, in the paragraph, Location is static, but Earth is not. i.e you can have

Location: Earth
Location: LA
Location: Mars
Stephan

You want to use the Element::ownText method.

String html = "<div>\n" + //
        "<p><strong>Location: </strong> Earth</p>\n" + //
        "</div>";

Document doc = Jsoup.parse(html);
Element p = doc.select("p").first();

if (p!=null) {
    System.out.println(p.ownText());
} 

OUTPUT

Earth

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select element whose child/grandchildren/.. contains an element with a specified pattern

From Dev

Select element whose child/grandchildren/.. contains an element with a specified pattern

From Dev

Select and deselect options in a select element based on a condition

From Dev

Select and deselect options in a select element based on a condition

From Dev

onclick select child element

From Dev

select child element jQuery

From Dev

select child element with jquery

From Dev

Javascript - Select first element of child of child of element

From Dev

jQuery - select child of child of element

From Dev

select child element without selecting parent element

From Dev

Iterate over a parent element and select a child element

From Dev

Select element except for specific child

From Dev

Select last child with specific element

From Dev

Not select Child class element (Jsoup)

From Dev

Select element except for specific child

From Dev

Specified element is already the logical child of another element. Disconnect it first”

From Dev

how to deselect all element in jquery?

From Dev

how to deselect all element in jquery?

From Dev

deselect mutliselection element using jquery

From Dev

In jQuery or JavaScript, select child element adjoining the parent

From Dev

how to select child of clicked element in jQuery?

From Dev

How to select a child element of parent by jquery selector?

From Dev

How do you select any child element?

From Dev

How to select only one child element in CSS?

From Dev

how to select child element in my test case

From Dev

Select element in css with nth-child

From Dev

Always select a parent element when clicking on a child

From Dev

How to select odd child of dl element with css?

From Dev

How do I select the nth child of an element?

Related Related

  1. 1

    Select element whose child/grandchildren/.. contains an element with a specified pattern

  2. 2

    Select element whose child/grandchildren/.. contains an element with a specified pattern

  3. 3

    Select and deselect options in a select element based on a condition

  4. 4

    Select and deselect options in a select element based on a condition

  5. 5

    onclick select child element

  6. 6

    select child element jQuery

  7. 7

    select child element with jquery

  8. 8

    Javascript - Select first element of child of child of element

  9. 9

    jQuery - select child of child of element

  10. 10

    select child element without selecting parent element

  11. 11

    Iterate over a parent element and select a child element

  12. 12

    Select element except for specific child

  13. 13

    Select last child with specific element

  14. 14

    Not select Child class element (Jsoup)

  15. 15

    Select element except for specific child

  16. 16

    Specified element is already the logical child of another element. Disconnect it first”

  17. 17

    how to deselect all element in jquery?

  18. 18

    how to deselect all element in jquery?

  19. 19

    deselect mutliselection element using jquery

  20. 20

    In jQuery or JavaScript, select child element adjoining the parent

  21. 21

    how to select child of clicked element in jQuery?

  22. 22

    How to select a child element of parent by jquery selector?

  23. 23

    How do you select any child element?

  24. 24

    How to select only one child element in CSS?

  25. 25

    how to select child element in my test case

  26. 26

    Select element in css with nth-child

  27. 27

    Always select a parent element when clicking on a child

  28. 28

    How to select odd child of dl element with css?

  29. 29

    How do I select the nth child of an element?

HotTag

Archive