Search code examples
jqueryappendto

jquery append and attr.appendTo


Why this code works:

$(this).append($(this).parent().find("div:not(.exit_block)").attr("id"));

and this not:

$(this).parent().find("div:not(.exit_block)").attr("id").appendTo($(this));

? Debugger writes that appendTo is not a function. How must I use appendTo in this situation? I want to append attribute id to content in $(this) using appendTo.


Solution

  • Your second line doesn't work because you're trying to call .appendTo on a value, not on a jQuery object.

    .attr docs

    Description: Get the value of an attribute for the first element in the set of matched elements.