views:

105

answers:

3

I am using a jquery click function:

Button code:

<input type="button" id="myButtton">

Jquery code:

$(document).ready(function(){ 
    $("#myButtton").click(function(){
        alert("Mybutton");
    });

This code works in Internet Explorer but does not work in Firefox.

What am I doing wrong?

A: 

Are you sure that element has an id attribute? Or does it have only a name attribute with a value of "myButton". In order to work cross browser the id attribute is mandatory, whereas name is optional (only IE and Opera AFAIK).

N.B.: My answer may seem idiot, but it was not the original poster that added the code example in the question (view edit history).

Ionuț G. Stan
A: 

My best guess is that you have other input with the same ID? Try using classes instead, or use jQuery's CSS selector like $('input[type=button]') instead.

I'd also recommend installing FireBug plugin for FireFox if you haven't done so already (http://www.getfirebug.com/). It'll help you debug JavaScript issues like this, and a whole lot more.

jay_soo
+4  A: 

In the code:

$(document).ready(function(){ 
    $("#myButtton").click(function(){
        alert("Mybutton");
    });

I believe it's missing another closing brace:

$(document).ready(function(){ 
    $("#myButtton").click(function(){
        alert("Mybutton");
    });
});
Jesse Dearing