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,479
  • 7
  • 36
  • 52

2 Answers2

3

Declare array something like this

var expression = new Array();
Shakti Singh
  • 81,083
  • 20
  • 131
  • 150
3

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

var expression = [];   //Array literal
SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933