dyk dyk - 1 year ago 132
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

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download