Reputation: 36
I'm using the following JS I found online to implement a responsive navigation. There is nothing on the source about having any errors in IE8, however I'm doing some compatibility testing in BrowserStack (Win7+IE8) and getting the "Object doesn't support this property or method" error. Here is the entire script:
<script>
$(function() {
var pull = $('#menu');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
});
$(window).resize(function(){
var w = $(window).width();
if(w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
</script>
And this is the line that IE8 doesn't like (character 6 specifically):
if(w > 320 && menu.is(':hidden')) {
Any help in solving this would be awesome, I'm still not the best at JS.
Upvotes: 2
Views: 18929
Reputation: 833
I hope you realize that single var statement doesn't apply to all of the variables. You are declaring global variables.
Upvotes: 2
Reputation: 707158
Just stop storing jQuery objects in globals at all. It doesn't cost much to just create them upon demand and you don't get into this lifetime/scoping issue that you had:
<script>
$(function() {
$('#menu').on('click', function(e) {
e.preventDefault();
$('nav ul').slideToggle();
});
});
$(window).resize(function(){
var menu = $('nav ul');
if($(window).width() > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
</script>
Some general design/code layout thoughts that apply here:
Upvotes: 0