JavaScript/jQuery - grabbing an integer from an element's id

前端 未结 10 541
青春惊慌失措
青春惊慌失措 2021-01-18 20:55

From the following markup.


      
10条回答
  •  太阳男子
    2021-01-18 21:56

    If you know that all your ids are prefixed by "link-", you can simply get the substring of the id:

    $("#my-div a").click(function(){
       alert(this.id.substr(5));
    });
    

提交回复
热议问题