javascript - Getting error when appending to documentFragment -
i'm getting error when creating document fragment, appending elements , returning fragment. i've used document fragments in past (abused them way beyond example) , have never run in error. in developer console lists source of error:
fragment.appendchild($balancenumber, $balancesign);
error
uncaught notfounderror: attempt made reference node in context not exist.
function
var constructbalancefragment = function(balance) { var $balancenumber, $balancesign, fragment, sign; fragment = document.createdocumentfragment(); $balancenumber = $('<span class="balance_number"></span>'); $balancesign = $('<span class="balance_sign"></span>'); if (balance > 0) { sign = "+"; $balancesign.addclass("positive_number"); } else if (balance < 0) { sign = "-"; $balancesign.addclass("negative_number"); } else { sign = ""; } $balancenumber.text(balance); $balancesign.text(sign); fragment.appendchild($balancenumber, $balancesign); return fragment;
edit
i have tried , still got same error before asks
fragment.appendchild($balancenumber); fragment.appendchild($balancesign);
this closer original , seems work, keeping in spirit of jquery:
$(fragment).append($balancenumber, $balancesign);
Comments
Post a Comment