tags:

views:

260

answers:

3

Hi

I have items in a table cell that gets toggled on and off.

An external button accepts a click and submits the selected cell values via ajax.

The problem is that I want to reset the toggle state for the selected cells.

I can easily unset the highlighting, but then need a double click to trigger the correct toggle.

Can the .toggle(odd, even) be reset or cycled via an external call?

Thanks

+1  A: 

.toggle() is the same as alternating between .show() and .hide() so just call .show() or .hide() depending on what the desired "reset" state is.

if you are using .toggle() to cycle through handlers then just unbind and rebind the toggle event.

Jon Erickson
The problem is that I use toggle in the 2 or more function alternation way.I then unset via another button and need to programmatically reset the toggle state of the set items.
Forkrul Assail
+1  A: 

I have not tested but, could it be done like this?



//reset the toggle state<br>
      $('#tablecell').unbind('click').toggle(fn1, fn2);<br>
      $('#tablecell').toggle(fn1, fn2);
Kai
Unbind and then reset the actual functions?
Forkrul Assail
A: 

I eventually solved this by selecting the already toggled list of elements.

I then call a .click on it.

Which seems like a bit of a workaround, but since I can't trigger the state of toggle. I settled for this.

Forkrul Assail