views:

101

answers:

1

I'm new to JQuery... this code doesn't work in IE7 but does in FF & Chrome. It says its giving me a syntax error, help!

$(function(){ $("#bClose").click(function() { $("#ContactRepeat").slideUp("normal"); });

$("#bContact").click(function() {
 if ($("#ContactRepeat").css("display") == "display"){
  $("#ContactRepeat").slideToggle("normal", function(){
   $("#ContactRepeat").slideToggle("normal");
  });
 }
 else {
  $("#ContactRepeat").slideToggle("normal");
 }
return false;
});

});

I'm using jQuery 1.2.6. Thank you for your help ahead of time

+1  A: 

The major flaw in your code is this line, btw:

$("#ContactRepeat").css("display") == "display"

It'll never be display. Maybe none or block. But it's better to do .is(':visible') or .is(':hidden')

Here's a revised snippet. I'm not seeing any syntax errors being reported when i run this through JSLint

$(function(){ 
    var crepeat = $("#ContactRepeat");

    $("#bClose").click(function() { $( crepeat .slideUp("normal"); });

    $("#bContact").click(function() {

        if (crepeat.is(':visible')){
                $crepeat.slideToggle("normal", function(){
                        $(this).slideToggle("normal");
                });
        }
        else {
                crepeat.slideToggle("normal");
        }
        return false;
    });

});
Paul Irish
Nice answer Paul, I'll just add that the :visible selector got more reliable (along with alot of other stuff) in 1.3.2. If you have the option, I would certainly consider moving that direction.
Alex Sexton