Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
problem editing CSS display attribute
Old 06-21-2008, 06:04 PM problem editing CSS display attribute
pealo86's Avatar
Super Spam Talker

Posts: 849
Name: Matt Pealing
Location: England, north west
Trades: 0
I have the following code:

CSS:
Code:
    
.box, .boxHide {
    border:#CCC solid 1px;
    width:300px;}
    
.boxHide {
    display:none;}
Javascript
Code:
function appear (element)
    {
        var element = document.getElementById(element);
        var elementStyle = element.style;
        
        if (elementStyle.display == 'none')
            {
                // make the element visible
                elementStyle.display = "block";
            }
        
        else
            {
                //make the element invisible
                elementStyle.display = "none";
            }
    }
But I seem to have to click twice in order for it to work properly. Ive figured out [through using the alert function to show the elements 'display:' property from the CSS] that nothing seems to be assigned to it. The alertbox just shows up blank.

Then, since its not equal to 'none'; is assigned 'none' to its display. Therefore it starts working after 2 clicks.

But I just cant figure out why element.style.display isnt equal to 'none' when Ive set it in the CSS??
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 06-21-2008, 06:13 PM Re: problem editing CSS display attribute
Novice Talker

Posts: 5
Trades: 0
Had this problem myself before, to fix it I removed the display from css and added it into the style tag and it worked.
Asiri is offline
Reply With Quote
View Public Profile
 
Old 06-21-2008, 06:16 PM Re: problem editing CSS display attribute
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
this line:
Code:
if (elementStyle.display == 'none')
is looking for the inline attribute style="display: none;". It doesn't know about the style in your external stylesheet when you check it this way, which is why you must click it twice for it to see that it is there.

***Edit*** oops, you beat me to it. Good job.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 06-21-2008 at 06:17 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-21-2008, 06:19 PM Re: problem editing CSS display attribute
pealo86's Avatar
Super Spam Talker

Posts: 849
Name: Matt Pealing
Location: England, north west
Trades: 0
ahhhh so it won't work with an external stylesheet? Thats horrible!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 06-21-2008, 06:30 PM Re: problem editing CSS display attribute
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The way I deal with it, to avoid writing inline styles to start out, is to load them dynamically on page load from within the script, or else (normally) to place the needed styles within classes, and simply switch the styles with the className method.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-21-2008, 06:46 PM Re: problem editing CSS display attribute
pealo86's Avatar
Super Spam Talker

Posts: 849
Name: Matt Pealing
Location: England, north west
Trades: 0
I get ya, thanks. Seems a bit wierd the way it doesnt work, after all; Im sure it worked when I used to use the visibility style?? ah well
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Reply     « Reply to problem editing CSS display attribute
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26531 seconds with 12 queries