michael2
9/11/2017 - 12:23 AM

Add class to button with current page link (allows you to hide, style differently when button links to current page) example http://www.he

Add class to button with current page link (allows you to hide, style differently when button links to current page)

example http://www.hellonightkids.com.au/our_collection.html

<script>
// Get the URL, split at the domain name
// Split creates an array, index 0 is everything from the start to the end of the domain
// Index 1 is the actual page name
var page = location.href.split("hellonightkids.com.au/")[1];
  // If page length is 0, we are on the home page, this will add the class to all
  // perform a check to make sure we are looking for indexOf something...
if(page.length > 0){
// Loop through every button
$(".butFrame").each(function(){
  // If the attribute "onclick" contains the pagename, the result of index of will 
  // be greater than 0, index of returns the starting character of the string
  if($(this).attr("onclick").indexOf(page) != -1){
    // add the active class to this div
    $(this).addClass("active");
  }
});
}
</script>