I am trying to understand the change in behavior of .appendTo() api in jquery 1.9.1 version from previous versions. In the upgrade guide it says
As of 1.9, these methods(
.appendTo
,.insertBefore
,.insertAfter
, and.replaceAll
) always return a new set, making them consistently usable with chaining and the.end()
method. Prior to 1.9, they would return the old set only if there was a single target element. Note that these methods have always returned the aggregate set of all elements appended to the target elements.
I tried with a simple usage of this api
<div class="test">hello
</div>
var $ = jQuery.noConflict();
var a =$("<p> hi </p>").appendTo("div.test").attr("style","background-color:red");
console.log(a);
Here is the fiddle link
I am appending a paragraph element to a div and then changing the background of the resulting element. I tried this with both 1.7.2 and 1.9.1 in both the cases the result after appending is the paragraph element.
But it has been explained in document that prior to 1.9 it will return old set(in my example old set refers to the div element I believe). I am definitely having a wrong idea about this.
Please help in correcting my understanding.
hi
").appendTo("div.test").end().attr("style","background-color:red")`. – meze Jul 25 '13 at 11:26hi
");` – vladkras Jul 25 '13 at 11:31