Rog
Rog

Reputation: 11

jQuery .hide function not working

Hy guys and hope you can help.

I have a very simple jQuery hide function that was working but some bugInTheRom has occured overnight and it no longer does. Effectively I'm trying to add a 'Patience' warning visible whilst some SWF loads.

Here's my call in the <head> section...

<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript">
function hidden() {
    $('.patience').hide();
};
window.onload=hidden;
</script>

and here's the class it affects...

<p class="patience">Please be patient, the interactive book below and the PDF links may take a while to fully load.</p>

and the associated CSS...

.patience {
    visibility: visible;
    background-color: #CCC;
    border: 1px solid #000;
    margin-right: 10px;
    margin-left: 10px;
}

Any ideas why it doesn't hide once the whole of the SWF has been loaded?

My thanks. R

Upvotes: 1

Views: 2985

Answers (5)

Rog
Rog

Reputation: 1

My stupid mistake!

Nothing wrong with the code I showed you but I discovered that I was calling <script type="text/javascript" src="js/jquery-1.6.1.js"></script>in the head and only the "js/jquery-1.6.1.min.js" script existed on my server.

Feel stupid now but thanks all who contributed.

Cheers Rog

Upvotes: 0

Alnitak
Alnitak

Reputation: 339786

Firstly - window.onload is the right place to put this handler - unlike $(document).ready() it will wait until all sub-frames, images, etc, have loaded.

What I don't know is whether window.onload will also wait for an SWF object to be loaded.

If it doesn't wait for the SWF, then the effect would be that your .patience div will disappear too early, since the rest of the page will have finished loaded.

It it does wait, but your div isn't disappearing at all, this suggests that you've simply got a trivial error somewhere in your real JS code that is preventing the .hide() from ever being called.

Since you've said that the div isn't disappearing, I would suggest that you've got the latter problem, in which case a few minutes with a JS debugger should reveal (no pun intended) the problem.

Upvotes: 1

Naftali
Naftali

Reputation: 146302

For one thing change window.onload=hidden; to $(function(){hidden();});

The new way i suggested is using jQuery's version of document ready which makes sure that the elements that you might want to affect are loaded and can be used.

Also i see nothing in your code which connects this hidden() function to any SWF load

See Fiddle: http://jsfiddle.net/maniator/XX8ym/

Upvotes: 1

Mu Mind
Mu Mind

Reputation: 11194

If you're having problems, I would switch to:

$(document).ready(function () {
    $(window).load(function () {
        $('.patience').hide();
    });
});

which might help everything initialize properly.

I'm not sure I understand how the SWF is related... perhaps you meant to say swf_elem.onload or something instead of window.onload?

Upvotes: 3

dev_musings
dev_musings

Reputation: 1181

May be your jQuery failed to load. Also, when using jQuery, use jQuery's $.ready instead of window.onload to ensure all things are in peace before trying to do anything!

Upvotes: 0

Related Questions