views:

57

answers:

2

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();
    }
});
+3  A: 

You are only removing it's class, so for example

<div class="someclass"></div>

will change into

<div></div>.

try

$('.someClass').remove();
Powertieke
A: 

I found the problem. window.location is an object so the .match method couldn't match anything from the regex. I had to use the .href property of window.location to 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.

Espresso