JQuery selectors for first li

前端 未结 4 468
旧时难觅i
旧时难觅i 2021-01-27 19:38

I need an onclick event, when the user clicks on the first li aka(Any Date).How do I select that element using jQuery?

4条回答
  •  天涯浪人
    2021-01-27 19:56

    Well it has an id so you can use that in your selector. You are targeting the link inside the li correct?

    $("#ui-id-2 a").click(function(){
     // function goes here
    
     return false; // the link itself has a behaviour associated with it so we want to stop that
    });
    

    Otherwise for something more generic you can use the :first-child selector.

    Note : While :first matches only a single element, the :first-child selector can match more than one: one for each parent.

    $("ul.ui-menu li:first-child a").click(function(){});
    

提交回复
热议问题