/    Sign up×
Community /Pin to ProfileBookmark

Getting JavaScript Error Message In IE?

I have this javascript code,

[code]function loadState() {
var state = $.cookie(‘toggleState’);
$(‘div.toggle’).each(function(i) {
$(this).toggle(state[i] == ‘Y’);
});
}[/code]

But im getting an error message in Internet Explorer “state is null or not an object”
on this line,

[code]$(this).toggle(state[i] == ‘Y’);[/code]

How do I fix this?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@BIOSTALLSep 29.2010 — Hi jrolson, Could you try something like so:

[CODE]function loadState() {
var state = $.cookie('toggleState');
$('div.toggle').each(function(i) {
var do_toggle = false;
if (state[i]!=null) {
if (state[i] == 'Y') { do_toggle = true; }
}
$(this).toggle(do_toggle);
});
}[/CODE]


I think the problem might be arising when the variable 'state' is not set. All i'm doing is checking if it exists or not. I haven't tested this but hopefully it should point you in the right direction.

Let me know how you get on ?
×

Success!

Help @jrolson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...