I'm trying to add a class to a li in jquery (or javascript). It works fine in FF and Google, but IE8 doesn't seem to recognize the code, because there's no class added.
I'm using jquery 1.9.1, you can see example here:
The thing is I'm using http://mediaelementjs.com/ to add audio (various songs) that on click is reproduced, each of these songs are wrapped in a li in javascript. That's why I need to add each li a class to assign a background-image to each song.
I tried the following, neither works:
/// first code ///
$(document).ready(function() {
$(".mejs li").each(function(i) {
$(this).addClass("at_" + (i+1));
});
});
/// second code ///
$(document).ready(function(){
var i = 1;
$(".mejs li").each( function() {
$(this).attr("class", "at_"+i);
i++;
});
});
/// third code ///
var elements = document.getElementsByTagName("li");
var nameClass = '';
for (i = 0; i < elements.length; i++) {
nameClass = elements[i].className+" at_"+i;
elements[i].className = nameClass;
}