Skip to content

Instantly share code, notes, and snippets.

@interfacecreation
Last active December 10, 2015 23:19
Show Gist options
  • Save interfacecreation/4508589 to your computer and use it in GitHub Desktop.
Save interfacecreation/4508589 to your computer and use it in GitHub Desktop.
Just a little snippet to check for segments in the url and add a switch statement to add classes.
$(document).ready (function() {
// Get segments and store in variables
var newURL = window.location.protocol + "://" + window.location.host + "/" + window.location.pathname;
var pathArray = window.location.pathname.split( '/' );
var segment_1 = pathArray[1];
// switch cases depending on the url segment and add an active class
switch (segment_1){
case "your_segment_value":
$("selector").addClass("active"); // do something
break;
case "your_other_segment_value":
$("#step2").addClass("active") // do something else
break;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment