comment 0

Javascript switch statement with a substring


I needed to set an active tab in a menu. You obviously can not do this with pure css, at least that I have found. I am using ASP.Net MVC so the url will always display what page I am on. What was really cool is that I could do this all in Javascript. I have done this before, but needed to test for a substring within the URL. Here is what I did:

What I didn’t realize is that the function actually needs to be named “test”. I tried different names and would get an error message stating that the function didn’t exist in RegExp. Once I named it “test” the error went away. If some one could explain this one to me I would be grateful.

Leave a Reply

Your email address will not be published. Required fields are marked *