I am generating a hyperlink inside a para in the following way:
<p id="category1"></p>
jQuery Code:
$(function () {
var link = [
["category1", "http://www.xyzabcxyz.com/apple", "Apple description comes here"],
["category2", "http://www.xyzabcxyz.com/banana", "Banana description comes here"],
["category3", "http://www.xyzabcxyz.com/apricots", "Apricots description comes here"],
["category4", "http://www.xyzabcxyz.com/peaches", "Peaches description comes here"]
];
$.each(link, function (e) {
if ($("#" + link[e][0])[0]) {
$("#" + link[e][0]).append('<a target="_blank" href="' + link[e][1] +
'">' + link[e][2] + '</a>');
}
});
});
Demo: http://jsfiddle.net/j2g411yk/
So far so good. Everything works.
I was wondering how to change my code so that it randomnly shuffles multiple products inside a category. Something like this:
$(function () {
var link = [
[["category1", "http://www.xyzabcxyz.com/apple", "Apple description comes here"],
"http://www.xyzabcxyz.com/pineapple", "Pineapple description comes here"],
"http://www.xyzabcxyz.com/lemon", "Lemon description comes here"]],
["category2", "http://www.xyzabcxyz.com/banana", "Banana description comes here"],
[["category3", "http://www.xyzabcxyz.com/apricots", "Apricots description comes here"],
"http://www.xyzabcxyz.com/Berries", "Berries description comes here"]]
["category4", "http://www.xyzabcxyz.com/peaches", "Peaches description comes here"]
];
$.each(link, function (e) {
if ($("#" + link[e][0])[0]) {
$("#" + link[e][0]).append('<a target="_blank" href="' + link[e][1] +
'">' + link[e][2] + '</a>');
}
});
});
So for one user it may show a hyperlink about Apple and for the other, it may be a hyperlink for Lemon. If the same visitor refreshes the page, a new product for the same cateogory should get displayed.
P.S: I want a random link but not to the extent where I have to use a cookie to keep a track if Visitor A has seen that link. It can be possible that the same user sees the same product twice on refresh and that's perfectly ok.