var down=function(a,b){alert(a)}
Array.prototype.sort.call(table.tBodies[0].childNodes,down)
Array.prototype.sort.call([0,1,2,3],down)
Why do I not get alerts from the first sort call?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Convert the
NodeListto an array first:and then call
sortnormally:It seems
sortcannot handle array-like objects. This is probably becauseNodeListdoes not provide any methods to change the list, butsortsorts the array in-place.Update: For more information, from the specification:
I assume
NodeLists don’t have these internal methods. But this is really just an assumption. It could also be that this is implementation dependent.I also suggest you use
.children[MDN] instead of.childNodesto only get element nodes. Update: Or.rows[DOM Spec] as @patrick suggests.