You have 2 carousels on your page and you use this JS to randomly show one or the other.
«hitting the back button does not cause the page to re-run javascript», as Taplar correctly said in comments. Now it seems like the page is returned to its state as it was before the document ready handler is executed...
EDIT
Since the .remove()
trick isn't working either...
I would try to use only one slider. But based on the random number, replace or not the image slide set.
So you have to have the image replacements in an array.
var replacementImageArray = ["assets/img/4.jpg", "assets/img/1.jpg", etc...]
Then on document ready, check the random number and proceed with replacement...
$(document).ready(function() {
var random = Math.floor(Math.random() * 2);
if (random === 0) {
$('#myCarousel').find("img").each(function(index){
$(this).attr("src", replacementImageArray[index]);
}
}
});
Disclaimer: the script above is an untested suggestion... Just as a strategy hint.
Bonus, a code "cosmetic" and performance hint:
if (Math.random() >= 0.5) {
The Math.random() function returns a floating-point, pseudo-random number in the range 0–1 (inclusive of 0, but not 1)
Documentation