jQuery how to find an element based on a data-attribute value?

后端 未结 9 1875
鱼传尺愫
鱼传尺愫 2020-11-22 01:02

I\'ve got the following scenario:

var el = \'li\';

and there are 5

  • \'s on the page each with a data-slide=numb
  • 9条回答
    •  猫巷女王i
      2020-11-22 01:26

      I have faced the same issue while fetching elements using jQuery and data-* attribute.

      so for your reference the shortest code is here:

      This is my HTML Code:

      This is my jQuery selector:

      $('section[data-js="carousel"]');
      // this will return array of the section elements which has data-js="carousel" attribute.
      

    提交回复
    热议问题