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?

Sparky
  • 4,769
  • 8
  • 37
  • 52

2 Answers2

3

Declare array something like this

var expression = new Array();
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
3

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

var expression = [];   //Array literal
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964