Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:44:19+00:00 2026-06-02T09:44:19+00:00

As title says i have some problems with IE8 and Javascript. It’s known about

  • 0

As title says i have some problems with IE8 and Javascript. It’s known about its bug in interpretation of global variables: simply it does not get them if you don’t declare as:

var variable1 = something;

The problem it’s i’m trying to make a script that change the body background clicking on a button and i need a global variable wrapping the actual status (what bg-x.png i’m loading). This script work on FF, Safari and Chrome but not, obviously, on IE. Help? (the problem is on the variable “status”)

$('#change').click(function() {
    var numStates = 2;
    var name = $(this).text();

    if(!(status)) {
        status = parseInt(1,10);
    }

    if(status<numStates) {
        status = parseInt(status,10) + 1;
    }
    else {
     status = parseInt(1,10);
    }


    alert(status);


    var bgvar = null;

    switch(parseInt(status,10)) {
        case 1: var bgvar = ' #7097ab url(./img/bg-' + status + '.png) top center repeat';
        var name = 'Pattern';
        break;
        case 2: var bgvar = ' #7097ab url(./img/bg-' + status + '.png) top center repeat-x';
        var name = 'Sfumato';
        break;
        default: alert('Default');
    }

    $('body').css({
        background:bgvar,
    });

    $(this).text(name);


}
);

Working code even with IE (Thanks to Zeta):

$('#change').click(function() {
   var numStates = 2;
   var name = $(this).text();

// If data-status isn't defined set it to the initial value
if($('body').data('status') === undefined)
    $('body').data('status',1);

// Extract the status
var status = parseInt($('body').data('status'),10);

// Handle the status
if(status < numStates)
    status++;
else
    status = 1;

// Save the status
$('body').data('status',status);




    switch(status) {
        case 1: bgvar = ' #7097ab url(./img/bg-' + status + '.png) top center repeat';
        name = 'Pattern';
        break;
        case 2: bgvar = ' #7097ab url(./img/bg-' + status + '.png) top center repeat-x';
        name = 'Sfumato';
        break;
        default: alert('Default');
    }

    $('body').css({
        background:bgvar,
    });

    $(this).text(name);


}
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:44:20+00:00Added an answer on June 2, 2026 at 9:44 am

    Since you’re already using jQuery you could use .data() instead of global variables:

    $('#change').click(function() {
        var numStates = 2;
        var name = $(this).text();
    
        // If data-status isn't defined set it to the initial value
        if($('body').data('status') === undefined)
            $('body').data('status',1);
    
        // Extract the status
        var status = parseInt($('body').data('status'),10);
    
        // Handle the status
        if(status < numStates)
            status++;
        else
            status = 1;
    
        // Save the status
        $('body').data('status',status);
    
        /* ... Rest of your code ... */
    

    Note that this won’t work in XML documents in IE (according to the jQuery doc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title pretty much says it. I have some methods that need to run
As the title says, I have a hidden border with some controls inside, and
As the title says, i am having some problems with serializing my auto generated
The title pretty much says it but here is some background: I have an
The title pretty much says it. I have a UITableViewController. I have some arrays
As title says. I am looking for some help with my .htaccess. I have
Pretty much what the title says really. We have some code that is .NET
I just want what my title says.I have already read all the previous similar
The title says it mostly. If I have an object in Python and want
The title says enough I think. I have a full quality BufferedImage and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.