I've noted some details, let me explain: --- 1. [CSS Selectors][1]. jQuery allows you to use them too: $("[id^='content-wrap']") --> will select all elements which id starts with 'content-wrap' --- 2. [Substring][2] is an available method of JavaScript: var number = "navItem15".substring(7); // will return what is after position 7.. // resulting the number "15" --- 3. To start your menu with the first position. [This is][3] the best way: (function(){ $("#navItem1").trigger("click"); })(); // using this approach, you won't need copy your code into a function as you did // this approach triggers the "click" event in the first menu automatically --- Well, hope you got it! Nice coding! [1]: http://www.w3schools.com/cssref/css_selectors.asp [2]: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/substring [3]: http://jsfiddle.net/VQtwa/22/