jquery first child selector code example

Example 1: firstElementChild jquery equivalent

$('#myList > li:first-child');
// or
$('#myList').children('li:first-child');
// or
$('#myList > li').first();
// or
$('#myList').children().first();
// and so on

Example 2: jquery first child

$('div:first-child')

Example 3: jquery first child

$( "li" ).first().css( "background-color", "red" );

Example 4: select xml child element with jQuery

var xmlString = "<route><name>Lakeway</name><abrv>LAKE</abrv><eta><time>00:30</time><dest>MAIN</dest></eta></route>",
xmlDoc = $.parseXML( xmlString ),
$xml = $( xmlDoc ),
$abrv = $xml.find( "abrv" ).text() == "LAKE" ? $xml.find( "abrv" ) : false;

var time = $abrv.next().children("time").text();
var dest = $abrv.next().children("dest").text();

alert(time + " " + dest);