How to get elements by a specific value of a custom attribute in jQuery?

后端 未结 4 1333
天命终不由人
天命终不由人 2021-01-19 16:28

I have a custom attribute called data-role and I\'d like to find all elements where data-role=\"content\" in jQuery.

4条回答
  •  一生所求
    2021-01-19 17:02

    jQuery select by attribute selector:

    $('[data-role="content"]')
    

    And for an array use .each(); instead of for

    $('[data-role="content"]').each(function(){
      alert($(this).html());
    });
    

提交回复
热议问题