Removing an Element on Certain Location
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)) {
$('.some开发者_JAVA技巧Class').removeClass();
}
});
You are only removing it's class, so for example
<div class="someclass"></div>
will change into
<div></div>.
try
$('.someClass').remove();
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.
精彩评论