[jQuery] Re: Use jquery before the DOM is ready?

2009-04-06 Thread Karl Swedberg
On Apr 5, 2009, at 11:30 PM, Hector Virgen wrote: Just curious, why would you want to avoid document.write()? Here's one reason: http://ln.hixie.ch/?start=1091626816count=1 --Karl Karl Swedberg www.englishrules.com www.learningjquery.com

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-06 Thread Hector Virgen
@Karl: Thanks, that sounds like a good reason to me :) I wasn't aware of XHTML not allowing document.write() @Ricardo: The $('head').append() approach looks great. -Hector On Mon, Apr 6, 2009 at 11:31 AM, Karl Swedberg k...@englishrules.comwrote: On Apr 5, 2009, at 11:30 PM, Hector Virgen

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-06 Thread Michael Geary
document.write() works fine in XHTML documents unless you serve the document with an XHTML MIME type, which is rarely done in practice. If you are doing that you must avoid document.write(). I'm a big fan of document.write(). It lets you accomplish some things very cleanly that you can't do at

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-06 Thread Michael Geary
document.write() can only be used while the document is open (i.e. while the page is loading), not in response to any event such as the load event. If you call document.write() in an event handler, the document has already been closed. So document.write() opens a *new* document to write into,

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-05 Thread Hector Virgen
Just curious, why would you want to avoid document.write()? -Hector On Sat, Apr 4, 2009 at 9:49 PM, Ricardo ricardob...@gmail.com wrote: If you want to avoid document.write, append should work just as well (the head element already exists): $('head').append('style type=text/css#mainimage

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
Try setting the opacity to 0 when you set it to visible. -Hector On Sat, Apr 4, 2009 at 4:15 PM, Derba ryancolantu...@gmail.com wrote: the css visible seems to make it visible before it has a chance to fade in, but I will tinker with it some to see if I can get it to work.

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Derba
That works a lot better. Thanks for putting up with my questions hector. On Apr 4, 8:21 pm, Hector Virgen djvir...@gmail.com wrote: Actually, it might be better to just start off with 0 opacity and not mess with the visibility property at all: document.write('style

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
No problem, Derba. Glad to hear it worked :) -Hector On Sat, Apr 4, 2009 at 4:27 PM, Derba ryancolantu...@gmail.com wrote: That works a lot better. Thanks for putting up with my questions hector. On Apr 4, 8:21 pm, Hector Virgen djvir...@gmail.com wrote: Actually, it might be better to

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread MorningZ
How about just using CSS on the image ? On Apr 4, 7:35 pm, Derba ryancolantu...@gmail.com wrote: I'm trying to have jquery set an image's opacity to 0. Then, while the image is fully loaded, it will fade the image in. It seems to work fine, unless the images have already been viewed in the

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Derba
I tried the document.write method you told me to try, but using it anywhere causes the whole webpage to load up as a blank page. I have NO idea whats happening.

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
You may want to try a different approach. For example, you could use javascript to add a new style rule to the CSS that sets the image to visibility: hidden. This would have to happen *before* the dom has finished downloading to ensure that it always hidden, so no need to wrap it in

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
My mistake, I don't think you can write to the document after it has loaded. Try this instead: document.write('style type=text/css#mainimage{visibility:hidden}/style'); $(window).load(function() { //when everything is finally loaded, fade image in $(#mainimage).css({visibility: 'visible'});

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Derba
scratch that, including the document.write line in $(window).load (function() causes some error while leads to just a blank page in the browser. Using the first line of document.write('style type=text/ css#mainimage{visibility:hidden}/style'); seems to work fine thought. On Apr 4, 8:03 pm,

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
I don't understand. How does that make the image useless? It should be visible by JS and non-JS browsers, except that JS browsers will see it fade in. Am I missing something? -Hector On Sat, Apr 4, 2009 at 3:55 PM, Derba ryancolantu...@gmail.com wrote: Well, I that was the first thing I

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Hector Virgen
Actually, it might be better to just start off with 0 opacity and not mess with the visibility property at all: document.write('style type=text/css#mainimage{opacity:0}/style'); $(window).load(function() { //when everything is finally loaded, fade image in $(#mainimage).animate({opacity: 1},

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Derba
the css visible seems to make it visible before it has a chance to fade in, but I will tinker with it some to see if I can get it to work.

[jQuery] Re: Use jquery before the DOM is ready?

2009-04-04 Thread Ricardo
If you want to avoid document.write, append should work just as well (the head element already exists): $('head').append('style type=text/css#mainimage { visibility:hidden }/style'); On Apr 4, 9:27 pm, Derba ryancolantu...@gmail.com wrote: That works a lot  better. Thanks for putting up with