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.