jQuery get the id/value of
  • element after click function
  • 后端 未结 4 1023
    忘了有多久
    忘了有多久 2020-11-28 04:59

    How can I alert the id of the

  • item clicked?

    • First
    • Second
  • 4条回答
    •  無奈伤痛
      2020-11-28 05:39

      you can get the value of the respective li by using this method after click

      HTML:-

      
      
      
          show the value of li
          
      
      
      
          
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10

      JS:-

      $("li").click(function ()
      {       
      var a = $(this).attr("value");
      
      $("#user").html(a);//here the clicked value is showing in the div name user
      console.log(a);//here the clicked value is showing in the console
      });
      

      CSS:-

      ul{
      display: flex;
      list-style-type:none;
      padding: 20px;
      }
      
      li{
      padding: 20px;
      }
      

    提交回复
    热议问题