addID in jQuery?

后端 未结 4 667
日久生厌
日久生厌 2020-12-01 01:02

Is there any method available to add IDs like there is for adding a class - addClass()?

4条回答
  •  旧时难觅i
    2020-12-01 01:43

    ID is an attribute, you can set it with the attr function:

    $(element).attr('id', 'newID');
    

    I'm not sure what you mean about adding IDs since an element can only have one identifier and this identifier must be unique.

提交回复
热议问题