If you want to see 1
(the text of the id
element within the book
element), use
alert($(this).find('id').text());
Live Example | Source
(Your formatting completely changes the question -- the importance of formatting correctly in the first place!)
Update:
I believe the only way to get this (other than writing your own DOM-to-XML serializer) (no, there's another, probably better way) is to wrap it in another element and use html
:
alert($("<x>").append(this).html()); // <== Probably dangerous
...but that will move the element out of the original document. So you can avoid that by cloning:
alert($("<x>").append(this.cloneNode(true)).html());
Live Example | Source