0

I have global variables:

          units = 0;
          majorUnits = 0; 
          supportUnits = 0;
          requiredUnits = 0;
          electiveUnits = 0;
          electiveUnitsStop = 0;
          pending = 0;
          percent = 0;
          supportPercent = 0;
          requiredPercent = 0;
          electivePercent = 0;

I use this variables on function:

      $("tr").click(function() {
        $(this).toggleClass("taken");
        if ( $(this).hasClass('taken') ) 
        { .....

Then I have a second function in which I set variables back to zero:

      $( "#clear-button" ).click(function() {
          units = 0;
          majorUnits = 0; 
          supportUnits = 0;
          requiredUnits = 0;
          electiveUnits = 0;
          electiveUnitsStop = 0;
          pending = 0;
          percent = 0;
          supportPercent = 0;
          requiredPercent = 0;
          electivePercent = 0;
          // $( "tr" ).click(); 
          //$("tr").find('taken').removeClass('taken');
          //$("table").closest('tr').find('.taken').removeClass('taken');
          //$("tr").removeClass();
          //taken.allInstances = [];
        });

As seen above in commented code I'm trying to remove all occurrences of class taken that might or might not be present in the rows of my html table.

How could I accomplish this ?!?!

I would really appreciate any help.

4

1 に答える 1

0

クラスまたは要素を削除しようとしていますか?

サブ要素からクラスを削除:

$('table#tablename .taken').removeClass('taken');

http://api.jquery.com/removeClass/

要素を完全に削除します。

$('table#tablename .taken').remove();

http://api.jquery.com/remove/

thisまた、HTML 構造によっては、テーブル名を指定する代わりに、ターゲティングと使用をより具体的にすることができます(またfindclosestなどを使用します) 。

于 2013-11-04T04:11:39.467 に答える