Get class list for element with jQuery

后端 未结 17 1835
粉色の甜心
粉色の甜心 2020-11-22 03:20

Is there a way in jQuery to loop through or assign to an array all of the classes that are assigned to an element?

ex.

17条回答
  •  独厮守ぢ
    2020-11-22 03:44

    Why has no one simply listed.

    $(element).attr("class").split(/\s+/);
    

    EDIT: Split on /\s+/ instead of ' ' to fix @MarkAmery's objection. (Thanks @YashaOlatoto.)

提交回复
热议问题