Ive created a loop to assign the class ‘last’ to every fifth element but for some reason .className doesn’t seem to work. I originally used .class but ie7 and ie8 error out at this. Can anyone advise how I can resolve this?
JS Snippet
success: function(response) {
var source = $("#calendar-template").html(),
template = Handlebars.compile(source),
gameHTML = '';
for (var i = 0, gameLength = response.data.games.length; i < gameLength; i++){
var thisGame = response.data.games[i];
console.log(thisGame);
thisGame.className = ((i+1) % 5 == 0) ? 'last' : '';
gameHTML += template(thisGame);
}
instance.selectors.dateWrapper.append(gameHTML);
deferredObject.resolve();
instance.displayGames();
},
Response
data: Object
games: Array[18]
0: Object
1: Object
2: Object
3: Object
...
Cheers
I could understand that you are using the handlebars library.
response.data.gamesis a object that contains the context for existent HTML content. The calltemplate(thisGame)will substitute some parts of the#calendar-templateelement. Probably you have a{{class}}as handlebar expression somewhere. So, YOU SHOULD usethisGame.classand notthisGame.className.Remember that you are not messing with a DOM element but with a handlebars context object.