I need an onclick event, when the user clicks on the first li aka(Any Date).How do I select that element using jQuery?
You can use any of the methods given below to select first li element.
1. using jQuery :nth-child selector It selects the child of the element using its position. The value 1 select the li item located at first position.
$( "ul li:nth-child(1)" ).click(function(){
//do something here
});
2. using jQuery :first selector It selects the first li item.
$( "ul li:first" ).click(function(){
//do something here
});
3. using jQuery :eq() selector The li element starts with index 0. To select first item, you have use 0 as its value.
$( "ul li:eq(0)" ).click(function(){
//do something here
});
See this: Get the First Element of li Using jquery for live examples.