Append child and get child's Match object
bagerman opened this issue · comments
Right now to construct
<books>
<book author="author1"/>
<book author="author2"/>
....
</books>
I'd do the following:
Match books = $("books");
for(i=0; i < 1000; i++) {
books.append($("book").attr("author", "author" + i));
}
It appears that
Is there a way to append a node to the existing Match object and get corresponding to the newly created node Match object back? I am thinking about doing something like this
books.append("book");
books.children().last().attr("author", "author" + i);
but am not sure if it's guarantied to get the last appended child.
Thanks for your suggestion. We're aware of this issue (#56). Thus far, we haven't yet fully thought through how to best resolve this. I like the API and would like to optimise only on the materialisation of the XML tree, not the API.
but am not sure if it's guarantied to get the last appended child.
Why not? If no one concurrently modifies your document? append()
appends at the end, and children().last()
provides the last child...
Closing this as a duplicate of #56