javascript - Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node' -
running error on dom manipulation
var prependdata = $('#income_ranges').children().first().clone(); var prependeddata = $('#income_ranges').children().last(); var list = document.getelementbyid("income_ranges"); list.insertbefore(prependdata, prependeddata); uncaught typeerror: failed execute 'insertbefore' on 'node': parameter 1 not of type 'node'.
i error when run code , dont know why. appreciated.
can't test right now, pretty sure error because switching between jquery objects , vanilla js objects. use .get()
on jquery object it's vanilla counterpart (see documentation).
so change last line to:
list.insertbefore(prependdata.get(0), prependeddata.get(0));
or go full jquery (much prettier in opinion):
var prependdata = $('#income_ranges > :first-child').clone(); var prependeddata = $('#income_ranges > :last-child'); prependdata.insertbefore(prependeddata);
Comments
Post a Comment