views:

77

answers:

1

Hi All, I have a jquery code(toggel) which is working fine in IE6 but not in FF3. what can be the reason or workaround.

 <button>Toggle Me</button>
  <p>Hi</p>
  <p>Learning JQuery</p>

Jquery:

 $(function() {
        $("button").click(function() {
            $("p").toggle("slow")
        });
    });

CSS:

p 
   { background:#dad;
     font-weight:bold;
     font-size:16px; 


     }
+1  A: 

I would be inclined to use

<input type="button" ID="button" value="Toggle Me" />

instead of

<button>

and then change your code to

 $(function() {
        $("#button").click(function() {
            $("p").toggle("slow");
        });
    });

You were missing a ; after toggle("slow") which IE may forgive you for but other browsers may be less forgiving.

Working Demo

Russ Cam
input type=button is bad example, button tag is for purpose. just need to have ID.
Thinker
Thanks it worked for me.
Wondering
@Thinker: I have tried <button id="button">Toggle Me</button>but it didnt work.any clue..
Wondering
<button> elements inside forms submit different values depending on the browser, therefore I tend to stick to <input> elements.
Russ Cam
I think <button> elements are better than inputs, as in most of the cases, they don't carry any information, and can contain other HTML tags (img, strong, etc). But that's another debate :)
Fabien Ménager