Tag Archives: $XXX is not defined

[Solved] JQuery each Method Error: $XXX is not defined

When using each method to traverse the array in JQ, the error $item is not defined is reported

Structure:

 <div class="right">
      <div class="img_bg rightOne" @click="clickLeft('Company Mission')">Company Mission</div>
      <div class="img_bg rightTwo" @click="clickLeft('Core Values')">Core Values</div>
      <div class="img_bg rightThree" @click="clickLeft('Corporate Spirit')">Corporate Spirit</div>
      <div class="img_bg rightFour" @click="clickLeft('Brand Slogan')">Brand Slogan</div>
    </div>

js:

 $('.right div').each(function(index,item){       
        	// var $this = $(item);
          // $this.removeClass('is_active_right');
          item.removeClass('is_active_right');
        })

Solution:

 $('.right div').each(function(index,item){       
          var $this = $(item);
          $this.removeClass('is_active_right');
        })