• 1
  • 2
  • 3
  • 4
  • 5
  • 6 <...">

    Delete first list item with jQuery

    I have the following list:

    <ul id="list"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> 

    How can I use jQuery to remove the first element of this list (i.e., number 1) and leave the remaining elements intact?

    I would have thought that this has a pretty simple solution, but it turned out to be harder than I expected to answer.

    +7
    source share
    2 answers
     $('#list li').first().remove(); 

    JsFiddle example

    Ref:

    You can also perform a similar effect using pure CSS3 (without JavaScript) with:

     #list li:nth-child(1) { display:none; }​ 
    +15
    source
     $("#list li:first-of-type").remove(); 
    +4
    source

    All Articles