I have a small jquery script designed to strip an element of a class. My site is running on wordpress however I am getting errors every time I try the window resize handler is called.
jQuery(document).ready(
function watchSize($) {
var $windowSize = $(window).width();
var $target = ('#WoodsworthResidenceLogo');
if ($windowSize < 960 && $target.hasClass('span_2')) {
$target.removeClass('span_2');
}
$(window).resize(
function() {
var $windowSize = $(window).width();
var $target = ('#myelementID');
if ($windowSize < 960 && $target.hasClass('span_2')) {
$target.removeClass('span_2');
} else if ($windowSize > 960 && $target.hasClass('span_2')){
$target.addClass('span_2');
}
});
});
It seems most of my error comes from the $target variable. Any ideas or suggestions, I'm very new to javascript and jquery. Any help would be appreciated.
EDIT:
I'm also unsure of the scope of the variables, thus I have them redeclared in the nested function.