0

I'm using the jquery method $(this).html() to get the value of a button.

It works fine when I assign the value to a variable (like x = $(this).html();)

But won't work when I try to assign the value to an array (like expression[1] = $(this).html();)

A

// expression = array();


$(document).ready(function()
                {
                    $(".operator").click(function(){

        expression[0] = $(this).html(); //
        alert(expression[0]);           // Won't work

        // x = $(this).html();          // Works
        // alert(x);                    //


                  });
               });

What am I doing wrong?

1
  • If you want to test the code online, it is here -> jsfiddle.net/m44Tn/9 Commented Jan 12, 2011 at 13:20

2 Answers 2

3

Your array doesn't exist.
You need to create it first:

var expression = [];   //Array literal
Sign up to request clarification or add additional context in comments.

Comments

3

Declare array something like this

var expression = new Array();

2 Comments

Thanks, I saw it. The comment I posted earlier (now edited) was to Shakti Singh
Don't forget the var. You don't want to pollute the global scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.