javascript - 查找包含特定 div 的部分元素的数据索引

标签 javascript jquery html css

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

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

最佳答案

试试这个:

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

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

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

    }

}

关于javascript - 查找包含特定 div 的部分元素的数据索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23917821/

相关文章:

javascript - 当一直滚动到 div 末尾时,无限滚动不起作用

javascript - 如何为每两个元素映射以进行 react ?

Javascript/ typescript : How to run code directly after the return statement in the same scope?

javascript - 具有未封闭 block 的引导依赖性错误

jquery-ui - JQuery 自动完成 : trigger <g:select onChange>

javascript - 通过添加零来保持字符串长度

javascript - 在函数运行之前如何隐藏 CSS?

PHP:根据 id 为正方形着色并从 db 获取数据

javascript - 获取字符串Jquery中标签中包含的字符串

html - 标签标签还是表格标签?