dillonbrannick
dillonbrannick

Reputation: 322

Javascript not working in IE

Just realised that my site does not work in IE correctly. It works perfectly in Chrome and Firefox. In IE the problem is, the elements effected by javascript, just aren't appearing. I have Javascript enabled, so I don't know how its any different from the other browsers.

It's when I'm using the toggle_visibility function:

function toggle_visibility_1(id) {
    var e = document.getElementById(id);
    if(e.style.display = 'inline') 
    e.style.display = 'none';
}
function toggle_visibility_2(id) {
    var e = document.getElementById(id);
    if(e.style.display = 'none') 
    e.style.display = 'inline';
}

The website is here: http://www.dillonbrannick.com/ of course, there won't be a noticeable problem unless in IE and if in IE it may not be obvious, so hopefully I've described well enough.

So It seems that I somehow fixed the problem works just as it should see here if you want: http://testerwebby.tumblr.com/ So I don't know what I did, but I'll soon have it rolled out to my website, Thanks for all the help.

Upvotes: 1

Views: 793

Answers (1)

Sampson
Sampson

Reputation: 268344

You're performing assignment, not comparison:

// Sets the value of display
if ( e.style.display = 'none' )

You should be using == (value) or === (value and type) to test equality:

// Tests the value of display
if ( e.style.display == "none" )

If all you want to do is toggle between inline and none, the following would perform that better:

function toggle_visibility(id) {
    var e = document.getElementById(id);
    e.style.display = (e.style.display === "none") ? "inline" : "none" ;
}

Demo: http://jsbin.com/uyawop/edit#javascript,html

Upvotes: 8

Related Questions