dyk dyk - 5 months ago 14x
Javascript Question

JavaScript cannot get firstChild

I am trying to get first child of my div "tick_list" to insert new element but it returns undefined.

$(function() {
var tick_list = $('#tick_list');

socket.on('tick', function(data){

enter image description here


tick_list is a jQuery object which does not have firstElementChild property.

You could use tick_list.children().eq(0) to get the first child (still a jQuery object).

There are many ways to get the first child, and here is a jsperf test for them: