0

I've got a very simple web page spinner using the Prototype JS framework:

Frame nav:

Event.observe(
    'doit',
    'click',
    function(){
      parent.window.frames.cont.spinner.removeAttribute('style');
    },
    false);

Frame cont (this is the first element within the <body>):

<div id="spinner" style="display: none;"></div>

CSS:

#spinner {
    width: 50px;
    height: 50px;
    position: fixed;
    top: 50%;
    left: 50%;
    background: url(spinner.gif) transparent no-repeat center;
    margin-left: -25px;
    margin-top: -25px;
    z-index: 2;
}

Quite simply, it's a fixed-position <div> centered on the cont frame, and hidden when the browser loads the page (also to avoid problems in non-JS browsers). When the user clicks a button in the nav frame, the style attribute is removed and the user sees the spinner until the next page takes over. This works just fine in Firefox, but IE 9 refuses to work. This is what I've found from their standard F12 interface:

  • There is only one element with ID spinner.
  • Running parent.window.frames.cont.spinner.removeAttribute('style') or parent.window.frames.cont.document.getElementById("spinner").removeAttribute("style") in the Console tab returns true but results in the next but one element being hidden! This is not reflected in the HTML tab in any discernible way - The hidden element still has style="display: block;".

I tried using Prototype's show(), and it worked in Firefox, but not in IE9...

3
  • 1
    document.getElementById("spinner").style.display = "block" Commented Sep 5, 2012 at 16:27
  • The DOM API (getAttribute/removeAttribute,etc) have historically had issues dealing with synthesized properties (the gap between the DOM text and the actual objects that can be accessed via JavaScript). This appears to be one such case. I highly recommend using CSS classes or "standard" CSS inline property manipulation. Commented Sep 5, 2012 at 16:38
  • @JohnnyMopp parent.window.frames.cont.spinner.style.display = 'block'; worked - Can you make your comment an answer? Commented Sep 6, 2012 at 7:29

2 Answers 2

1

Instead of trying to remove the style attribute, just set the "display" property to "block".

document.getElementById("spinner").style.display = "block"
Sign up to request clarification or add additional context in comments.

Comments

1

Why remove the style attribute when it's much easier to add/remove classes? And anyways, if all you're trying to do is show/hide a div, why not just change the "display" style property only?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.