I have multiple divs with a class of type-aud. The divs don’t have an ID. I can’t perform a click function and then use (this) as it has to be on page load.
Each div has a attribute called file which I’m assigning to a variable and then placing it into an html5 audio tag. I need the SRC to be unique to the div.
var item = $('.type-aud');
path = item.attr('file'),
html = '<audio controls><source src="'+path+'" type="audio/mpeg" class="audio"></audio>',
playerClass = item.find('.audio');
if (!playerClass.hasClass('audio')) {
item.append(html);
}
Just use
.each()where you’d otherwise use.click().