My function is supposed to copy insides of element twice, and append them, but for some reason jQuery stops executing after first append. I do not understand why.
$(".testowyUl").prepend(function () {
var $temp = $(this).children().clone();
var $temp2 = document.createElement("div");
$temp2.append($temp);
$temp2.append($(this).children().clone());
return $temp2.children();
});
Try:
var $temp2 = $("<div>");
instead of:
var $temp2 = document.createElement("div");
to create a jquery object. As there is no method "append" in DOM element.
you are calling append on a non Jquery object at
$temp2.append($temp);
resulting in
Object #<HTMLDivElement> has no method 'append'
you could try by using
var $temp2 = $("div");
instead of
var $temp2 = document.createElement("div");
see a working fiddle here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.