jquery : Get html content between child and end of its parent

abhinsit

I have a div in the following structure

    <div id="article-content">
        <p>content of article</p>
        <h3 id="last-heading"></h3>
        <p>Content part 1 of last heading</p>
        <p>Content part 2 of last heading</p>
        <a href="http://www.google.co.in">Link</a>
        <div class="article-img"><img src="http://cdn4.mos.techradar.futurecdn.net//art/Watches/Samsung/GearLive/Review/samsung-gear-live-watch-review-623-80.jpg"/></div>...

..
..
..
    </div>

I want the following html content in output:

 <p>Content part 1 of last heading</p>
        <p>Content part 2 of last heading</p>
        <a href="http://www.google.co.in">Link</a>
        <div class="article-img"><img src="http://cdn4.mos.techradar.futurecdn.net//art/Watches/Samsung/GearLive/Review/samsung-gear-live-watch-review-623-80.jpg"/></div>...

..
..
..

ie. the html content after div with id last-heading until.
How to achieve this using jQuery
Please note: the content is dynamic. Only reference we have is id :last-heading and we have to find complete html content from that id till end of its parent.

Rajaprabhu Aravindasamy

Try to select the relevant element and use outerHTML property of it,

$('#article-content > p').slice(-2).map(function () {
    return this.outerHTML;
}).get().join('')

DEMO

Or if you want to select the paragraph elements particularly after one element, then use,

$('#last-heading ~ p').map(function () {
    return this.outerHTML;
}).get().join('');

DEMO

As per your new requirement, you can use tilde followed by nothing selector.

$('#last-heading ~').map(function () {
    return this.outerHTML;
}).get().join('');

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get the parent element html along with child content

From Dev

How to get parent as well as child's html in jquery

From Dev

click on parent except one of its child - jquery

From Dev

Get child element of parent with jquery

From Dev

jquery copy html content without the child content

From Dev

SimpleXML get Element Content between Child Elements

From Dev

Get the child of an HTML element by its XPath

From Dev

Get the child of an HTML element by its XPath

From Dev

Cast parent to its child

From Dev

child not stretching to its parent

From Dev

Get Exact child of their parent element. Jquery

From Dev

jquery get text of the parent li by their child li

From Dev

Is there always an Adorner Layer between a parent content control and its children?

From Dev

jQuery: give each <figure> parent the same width as its <img> child

From Dev

How to get the left and top position of a child element of its parent

From Dev

Get parent object plus its child count without anonymous type

From Dev

Make child div fit its content while its parent has scrollbars?

From Dev

JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain

From Dev

How to get child element of another child of the same parent with jQuery/JS

From Dev

Xpath to get content of parent tag and child tag together

From Dev

Make a div child have parent's right end as its zero position for start?

From Dev

differentiate the clicks between parent and child using javascript/jquery

From Dev

Having a child modify its parent

From Dev

parent node losing its child

From Dev

Center child to the center of its parent

From Java

How to get the parent child relationship between connected mxgraph

From Dev

How to get Angular 2 communication between child and parent component to work?

From Dev

How to get value between parent and child node using xpath?

From Dev

Get String between 2 strings, and the end of the parent string

Related Related

  1. 1

    Get the parent element html along with child content

  2. 2

    How to get parent as well as child's html in jquery

  3. 3

    click on parent except one of its child - jquery

  4. 4

    Get child element of parent with jquery

  5. 5

    jquery copy html content without the child content

  6. 6

    SimpleXML get Element Content between Child Elements

  7. 7

    Get the child of an HTML element by its XPath

  8. 8

    Get the child of an HTML element by its XPath

  9. 9

    Cast parent to its child

  10. 10

    child not stretching to its parent

  11. 11

    Get Exact child of their parent element. Jquery

  12. 12

    jquery get text of the parent li by their child li

  13. 13

    Is there always an Adorner Layer between a parent content control and its children?

  14. 14

    jQuery: give each <figure> parent the same width as its <img> child

  15. 15

    How to get the left and top position of a child element of its parent

  16. 16

    Get parent object plus its child count without anonymous type

  17. 17

    Make child div fit its content while its parent has scrollbars?

  18. 18

    JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain

  19. 19

    How to get child element of another child of the same parent with jQuery/JS

  20. 20

    Xpath to get content of parent tag and child tag together

  21. 21

    Make a div child have parent's right end as its zero position for start?

  22. 22

    differentiate the clicks between parent and child using javascript/jquery

  23. 23

    Having a child modify its parent

  24. 24

    parent node losing its child

  25. 25

    Center child to the center of its parent

  26. 26

    How to get the parent child relationship between connected mxgraph

  27. 27

    How to get Angular 2 communication between child and parent component to work?

  28. 28

    How to get value between parent and child node using xpath?

  29. 29

    Get String between 2 strings, and the end of the parent string

HotTag

Archive