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
Hide Element Before DOM Loads ?
Old 07-31-2008, 08:50 PM Hide Element Before DOM Loads ?
Experienced Talker

Posts: 33
Trades: 0
Greetings,

The following code hides some DIV elements which can later be displayed depending on user action.

The problem is, the DIV elements are displayed on the web page for a brief moment and then hidden. This is NOT the effect I want. The DIV elements should be hidden, not displayed for a brief moment and then hidden.

window.onload approach:

Code:
/*window.onload = function() {
hideElementsOnLoad();
}
Code:
function hideElementsOnLoad () {
// When the page loads, hide the form type help list and each form type.
var formTypeHelpList = document.getElementById("formtypehelp");
var uniGroupForm = document.getElementById("unigroupform");
var uniAffilForm = document.getElementById("uniaffilform");

formTypeHelpList.style.display="none";
uniGroupForm.style.display="none";
uniAffilForm.style.display="none";
}
So, I looked into using Prototype.js to solve the issue of the DIV elements being displayed for a brief moment then hidden. Using Prototype.js, the code above can be replaced with this. The benefit being, the elements are hidden right after the DOM loads but before images are loaded.

Code:
document.observe("dom:loaded", function() {
// When the page loads, hide the form type help list and each form type.
$('formtypehelp', 'unigroupform', 'uniaffilform').invoke('hide');
});
Unfortunately, Prototype's way still results in the elements being displayed on the page for a brief moment and then hidden. It's the same result the window.onload approach produced. :-(

Another approach would be to hide the DIV elements by default, by using CSS (display:none. The DIV elements could then be displayed by using JavaScript (display:block. But I would prefer not to use this approach since the DIV elements would not be visible to a JavaScript disabled device.

Perhaps it is possible to hide the DIV elements as the DOM is loading?

I am seeking suggestions on how to solve this problem. Thank you in advance.
nick1 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-31-2008, 09:05 PM Re: Hide Element Before DOM Loads ?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
create and load the elements using the DOM, and use the <noscript></noscript> element to duplicate the hidden elements for non-js user agents.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-31-2008, 10:13 PM Re: Hide Element Before DOM Loads ?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Or you could put your script at the bottom of the page instead of in the onload event. That way it will load as soon as the HTML is done, and before the images are finished.

Usually, if I do it this way, I place a single class on the <body> and then create CSS rules that take care of the rest. That way, the results are already cached, and the action is almost instant.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 07-31-2008 at 10:15 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Hide Element Before DOM Loads ?
 

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.18458 seconds with 12 queries