views:

192

answers:

2

MY javascript: Updated Again.

  $('.calc').change(function(){
   var classArray = $(this).attr('class').split(',');

   $.each(classArray, function(){
    alert(classArray);
    });
   });

And the input:

<input type="text" class="calc R#r# C#i#" />

The pound signs are variables, I'm using ColdFusion.

What I need to be able to do is successfully take each class and place them in an array. That way I can use that to do the required calculations for the entire table.

Help would be appreciated.

Thanks

+5  A: 

You could simply split the class attribute value, using space as the separator:

$('.calc').change(function(){
  var classArray = $(this).attr('class').split(' ');
});

Edit: I think that you want to do this.

$('.calc').change(function(){
  var classArray = $(this).attr('class').split(' ');

  $.each(classArray, function(){
    alert(this);
  });
});

Try this running example.

CMS
Didn't work. I'm still only returning 1 array object.
Michael Stone
That got me to return 3 objects, but all of which were calc R1 C1. What I need to display is: calc in it's own box, R1 in it's own box, and C1 in it's own box.
Michael Stone
Yeah it did. Thanks! I had my other one left in the code and it was breaking, but it worked!
Michael Stone
You're welcome!
CMS
A: 

CMS' answer definitely works for me. I doubt this is a browser issue but I suppose that's a possibility?

theIV