Check if current url matches string

I am trying to check if a link exists in the url of the current page in the menu.

var thisUrl = window.location.href;

$("ul.leftmenu li a").each(function() { 

  var thisHref = $(this).attr('href');

  if (thisUrl === thisHref) { 

    // matches




This works as long as the current window location url does not contain _GET variables. How do I change this to ignore the _GET variables at the current address?


source to share

1 answer

You can remove part of the query string from href

. For example, for example:

var thisUrl = window.location.href.replace(, '');

property is a substring of GET parameters, i.e. ?param=value&param2=etc




All Articles