Got it! I forgot to put .length after $titleArray and I used appendTo() instead of prependTo(). Although the code doesn’t look so elegant now. But it’s a good start.
var $titleArray = $('.title');
for (var i = 0 ; i < $titleArray.length; i++){
var $imageWrapper = $($titleArray[i]).parent().prev();
$($titleArray[i]).prependTo($imageWrapper);
};
solved DOM manipulation with JavaScript or jQuery by moving element inside of its sibling [closed]