Button problem

Button problem

I'm trying to change the text on a series of buttons which are located in a series of dynamically added forms. The idea is that you can open and close the forms you need, but when you close one form it will automatically also close all of its sub forms as well. All this works fine, but now I need to be able to change the text of the buttons as well... and this for some reason that is beyond me just will not work.

Each button has the following onclick event...

  1. javascript:jQuery.ButtonManager($('button#'buttonId'), $('div#divId button'))
...and  the plugin method looks like this...

  1. $.ButtonManager = function(button, buttons) {
  2. if (button.text() == 'Open')
  3. button.text('Close');
  4. else
  5. button.text('Open');

  6. buttons.each(function(i) {
  7. if (this.text() == 'Open')
  8. this.text('Close');
  9. else
  10. this.text('Open');
  11. });
  12. }
The first button works fine and changes text like I want it, but when I try and loop through the list of buttons I get an error message saying the text is not function. I've tried to check the type of them and the first one that works is show up as [object Object] where as the ones in the loop that doesn't work shows up as [object HTMLButtonElement].

What am I doing wrong?