tags:

views:

76

answers:

2

Hi everyone,

I've bind .click events on some section headers, so that when a user clicks on one of those headers, the section appears/disappears.

So far so good, but for some reason, when I go offline, that doesn't work anymore.

I don't understand such a behaviour, could anyone enlighten me?

Here's the code:

<script src="jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>

    <script>
    $(function(){

    $("#contactInfoHeader").click(function(){
        if($("#contactInformation").is(":visible")){        
            $("#contactInformation").fadeOut();
        }else{  
            $("#contactInformation").fadeIn();
        }   
        resizeWidget();
    });

    });
    </script>

    <h3 id="contactInfoHeader">Contact Information</h3>
    <div id="contactInformation">Telephone:XXXXXX</div>
A: 

You have some code inconsistency, or you're mistaken it works.

That should be in document.ready, as well:

$(function() {
/* your code */
});

Otherwise it doesn't attach the click event to anything, since the element is not there at runtime.

meder
jQuery works correctly when online, I just forgot to post the whole thing. Please see my updated question.
Pedro
Do you have the jQuery source locally? Get errors?
meder
jQuery sources are locally stored. No errors showing up in Firebug.
Pedro
You need to provide more information. Try `alert`s and make sure code is executing.
meder
Pedro
+1  A: 

in jQuery 1.4.x you should use this format for attaching handlers to the ready event.

$(document).ready(function(){
  //add your stuff here
});

or your can keep the $(handler); syntax, but you'll need the closing paren.

<script>
$(function(){

  $("#contactInfoHeader").click(function(){
      if($("#contactInformation").is(":visible")){        
          $("#contactInformation").fadeOut();
      }else{  
          $("#contactInformation").fadeIn();
      }   
      resizeWidget();
  });

});//ADDED ")" here!
</script>
scunliffe
This is the solution. @pedro: you need to make sure to wait for all tags to be loaded, otherwise your selector will just return an empty collection and not raise an error.
dguaraglia
I'm sorry I haven't been clear: jQuery DOES work when online. I just forgot to include my closing parenthesis while editing my question. The problem only appears as soon as I check "Work offline"
Pedro