jQuery to return the wrapper of the content instead of only the content

Greeso

Assume I have the following HTML

<articles>

    <article id="a1">
        <!-- Content of article with id="a1" -->
    </article>

    <article id="a2">
        <!-- Content of article with id="a2" -->
    </article>

    <article id="a3">
        <!-- Content of article with id="a3" -->
    </article>

</articles>

Using jQuery, I did the following

var x = $("#a2").html();

Now, the variable x will contian:

<!-- Content of article with id="a2" -->

However, I like to have x contain:

<article id="a2">
    <!-- Content of article with id="a2" -->
</article>

I tried:

var x = $("#a2").parent().html();

but this returned all three articles, which is not what I want. I only want article a2. How can I do that?

Thanks.

Rajaprabhu Aravindasamy

Try to use the .outerHTML property,

var x = $("#a2")[0].outerHTML;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Xpath: return only nodes with content

From Dev

return OK (200) instead of NO_CONTENT (204)

From Dev

jQuery: Load content only on hover

From Dev

jquery content only showing once

From Dev

Content alignment inside wrapper

From Dev

Make content visible only after using jquery to copy html content

From Dev

Ajax Return data Do not repeat content in jquery

From Dev

jQuery on click only works on dynamically generated content

From Dev

how to only change content in jquery mobile?

From Dev

jQuery .load() function only changes content once

From Dev

jQuery load div content only when selected

From Dev

how to only change content in jquery mobile?

From Dev

Sidebar wrapper not expanding with page-content-wrapper

From Dev

PHP file_get_contents and stream return warning instead of content

From Dev

Content Wrapper Problmes with CSS styling

From Dev

Tinymce 4 inline css content applied to page instead of div only

From Dev

Make innosetup copy the full folder instead of only its content

From Dev

Append jQuery autocomplete data to textarea content instead of overwriting it

From Dev

jQuery's .prepend is replacing my content instead of adding it to the beginning

From Dev

Return content of read-only <input type=text>

From Dev

How to hide content of previous and next siblings in a certain wrapper but not of clicked div in jQuery?

From Dev

Content negotiation to return HTML

From Dev

Signalr to return content

From Dev

Return content of multimap

From Dev

using "return Content" in Webmatrix

From Dev

jQuery select option - display content only for a specific option

From Dev

Jquery mobile: How to set panel push content only not header and footer?

From Dev

JQuery. Only apply function to associated content/divs

From Dev

Loading content only

Related Related

  1. 1

    Xpath: return only nodes with content

  2. 2

    return OK (200) instead of NO_CONTENT (204)

  3. 3

    jQuery: Load content only on hover

  4. 4

    jquery content only showing once

  5. 5

    Content alignment inside wrapper

  6. 6

    Make content visible only after using jquery to copy html content

  7. 7

    Ajax Return data Do not repeat content in jquery

  8. 8

    jQuery on click only works on dynamically generated content

  9. 9

    how to only change content in jquery mobile?

  10. 10

    jQuery .load() function only changes content once

  11. 11

    jQuery load div content only when selected

  12. 12

    how to only change content in jquery mobile?

  13. 13

    Sidebar wrapper not expanding with page-content-wrapper

  14. 14

    PHP file_get_contents and stream return warning instead of content

  15. 15

    Content Wrapper Problmes with CSS styling

  16. 16

    Tinymce 4 inline css content applied to page instead of div only

  17. 17

    Make innosetup copy the full folder instead of only its content

  18. 18

    Append jQuery autocomplete data to textarea content instead of overwriting it

  19. 19

    jQuery's .prepend is replacing my content instead of adding it to the beginning

  20. 20

    Return content of read-only <input type=text>

  21. 21

    How to hide content of previous and next siblings in a certain wrapper but not of clicked div in jQuery?

  22. 22

    Content negotiation to return HTML

  23. 23

    Signalr to return content

  24. 24

    Return content of multimap

  25. 25

    using "return Content" in Webmatrix

  26. 26

    jQuery select option - display content only for a specific option

  27. 27

    Jquery mobile: How to set panel push content only not header and footer?

  28. 28

    JQuery. Only apply function to associated content/divs

  29. 29

    Loading content only

HotTag

Archive