Refactoring JavaScript to jQuery

112
May 23, 2017, at 06:27 AM

I'm having trouble refactoring my vanilla JavaScript to jQuery and would appreciate any and all help regarding my situation. I'm a bit stuck on how to refactor the albumImage function (and everything inside it) after having refactored the DOM selectors in the first code block to jQuery syntax.

var setCurrentAlbum = function(album) {
  $albumTitle.text(album.title);
  $albumArtist.text(album.artist);
  $albumReleaseInfo.text(album.year + ' ' + album.label);
  $albumImage.attr('src', album.albumArtUrl);
  $albumSongList.empty();
  for (var i = 0; i < album.songs.length; i++) {
  var $newRow = createSongRow(i + 1, album.songs[i].title, album.songs[i].duration);
    $albumSongList.append($newRow);
    }
};

var $albums=[album1, album2, album3];
var $index = 1;
$albumImage.on("click",function(event){
  setCurrentAlbum($albums[index]); 
  index++; 
  if ($index == $albums.length) { 
    $index = 0;
};
});
READ ALSO
Sort isotope filtering result in alphabetical and numerical order

Sort isotope filtering result in alphabetical and numerical order

I have found this amazing script: http://fiddlejshell

94
Select text again after execCommand execution

Select text again after execCommand execution

I'm building a text editor using jQuery

90
Include imagesloaded in infiniteajaxscroll plugin

Include imagesloaded in infiniteajaxscroll plugin

I have several masonry isotope grids on my pageNow I implemented successfully the jquery-ias pagination plugin for some of them

94
How to disable changing GoJS diagram after page refreshing?

How to disable changing GoJS diagram after page refreshing?

My question will be simpleI'm new in GoJS diagrams building

99