找到包含特定div的section元素的data-index

时间:2014-05-28 17:07:38

标签: javascript jquery html css

我有一个单页面应用程序,用<section>个元素分隔它的页面。内容从后端动态输出。我如何使用jQuery遍历应用程序并查看包含div元素$('.narration_audio')的节的数据索引。

基本上我想要完成的是当用户来到包含div元素的页面(部分)以显示标题中的音频播放器时。否则会使音频播放器变灰。

2 个答案:

答案 0 :(得分:0)

您可以采用How to get the data-id attribute?使用$(this).attr("data-index")$(this).data("index")

中的类似方法

答案 1 :(得分:0)

试试这个:

$("section").each(function() {

    var this_el = $(this);
    if (this_el.find('.narration_audio').length) {

         var the_data_index = this_el.data('index');

    }

}
相关问题