Get class list for element with jQuery

后端 未结 17 1602
粉色の甜心
粉色の甜心 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:36

    The question is what Jquery is designed to do.

    $('.dolor_spec').each(function(){ //do stuff
    

    And why has no one given .find() as an answer?

    $('div').find('.dolor_spec').each(function(){
      ..
    });
    

    There is also classList for non-IE browsers:

    if element.classList.contains("dolor_spec") {  //do stuff
    

提交回复
热议问题