How to append a listitem in first position of list using Jquery

后端 未结 3 982
醉酒成梦
醉酒成梦 2021-02-12 19:06

How to append a listitem in first position of list using Jquery?

  • First
  • Second
3条回答
  •  悲哀的现实
    2021-02-12 20:10

    This snippet will solve the problem. Or go to the link to learn more.

    $('#mylist').prepend('
  • New Item
  • '); //use jQuery's prepend method.

    $('button').on('click',function(){
      $('#mylist').prepend('
  • New Item 1 added
  • ') });
    
    
      
      
      
    • First Item
    • Second Item
    • Third Item
    • Fourth Item

提交回复
热议问题