.cur{ background:#5fb878; font-weight:bold; } var urlstr = location.href; //alert(urlstr); var urlstatus=false; $("#menu a").each(function () { if ((urlstr + '/').indexOf($(this).attr('href')) > -1&&$(this).attr('href')!='') { $(this).addClass('cur'); urlstatus = true; } else { $(this).removeClass('cur'); } }); if (!urlstatus) { $("#menu a").eq(0).addClass('cur'); }