Let’s say the window’s location is on htt://stackoverflow.com/index.php, I want to remove an element in the index page with jQuery. This is what I have and it’s not working:
$(document).ready(function() {
var location = window.location;
var locQuery = /index/i;
if (location.match(locQuery)) {
$('.someClass').removeClass();
}
});
I found the problem.
window.locationis an object so the.matchmethod couldn’t match anything from the regex. I had to use the.hrefproperty ofwindow.locationto get a match.var location = window.location.href; var locQuery = /index/i; if (location.match(locQuery)) { $('.someClass').remove(); }I hope I use the right terms. I’m new to JavaScript.