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

后端 未结 9 1568
鱼传尺愫
鱼传尺愫 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条回答
    •  孤独总比滥情好
      2020-11-22 01:20

      in case you don't want to type all that, here's a shorter way to query by data attribute:

      $("ul[data-slide='" + current +"']");
      

      FYI: http://james.padolsey.com/javascript/a-better-data-selector-for-jquery/

    提交回复
    热议问题