I have the following code that checks the value of a variable and then applies the correct id attribute accordingly. The value of menuLink will have the same value of one of the parts of .mainmenu a href path name.Is there a way to simplify this so it can search the href path of .mainmenu a instead of explicitly stating each one?if (menuLink == whatsnew) {    $('.mainmenu a:eq(1)').attr('id', 'active').addClass(disable);} else if (menuLink == products) {    $('.mainmenu a:eq(2)').attr('id', 'active').addClass(disable);} else if (menuLink == contact) {    $('.mainmenu a:eq(3)').attr('id', 'active').addClass(disable);} etc.....
Applying an id attribute based on a variable's value
javascript;jquery
What you need is an array!And to remember that you can dynamically construct jQuery selectors.Then you need to loop through the array and search for the matching menuLink:var links = [whatsnew, products, contact];for (var i = 0; i < links.length; i++) {    if (menuLink == links[i]) {        var jqueryEq = i + 1;        $('.mainmenu a:eq(' + jqueryEq + ')').attr('id', 'active').addClass(disable);    }}However, you might want to consider a significantly simpler approach... what if you give the whatsnew, products and contact a matching id or class? Then the code could be as easy as:$('.mainmenu .' + menuLink).attr('id', 'active').addClass(disable);