I have this code:
var mods1 = ['a', 'b', 'c', 'd'];
var mods2 = ['1', '2', '3', '4'];
var mods3 = ['js', 'hates', 'me', ':('];
jQuery('div').append('<ul class="modlist"></ul>');
jQuery.each(mods1, function(i) {
jQuery('<li/>').html(mods1[i]).appendTo('.modlist');
});
I need to use a different variable (mods1, modsN,…) depending of the URL where this script is used.
The URLs always have the same structure:
http://www.example.com/NUMBER/
http://www.example.com/NUMBER/example/
http://www.example.com/NUMBER/example/example
The “number” part is the one I can use to differentiate between pages.
jsFiddle with my example code running: http://jsfiddle.net/RZHxz/
Try this:
I’ve made the
modsinto an array as that’s how you’re effectively accessing them anyway, also, theeach()function passes the value to the handling function as a parameter, so you don’t need to go off to the array again.Example fiddle