0

I have a single page application that separates its pages by <section> elements. Content is being outputted dynamically from the back end. How would I loop through the application using jQuery and see the data-index of a section that contains a div element of $('.narration_audio').

Basically what I'm trying to accomplish is when ever a user comes to the page (section) that contains that div element to show the audio player in the heading. Otherwise grey out the audio player.

display-name-is-missing
  • 4,424
  • 5
  • 28
  • 41
Dondada
  • 421
  • 9
  • 25

2 Answers2

0

You can take a similar approach seen in How to get the data-id attribute? Using $(this).attr("data-index") or $(this).data("index")

Community
  • 1
  • 1
soloidx
  • 729
  • 6
  • 12
0

Try this:

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

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

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

    }

}
display-name-is-missing
  • 4,424
  • 5
  • 28
  • 41