I'm not sure why this JQuery String isn't working

54 views Asked by At

I'm trying to do this:

"If the reference in the div with the class 'cart_ref' is equal to 'MAG04WH30' then hide up and down arrows with class names 'cart_quantity_up', 'cart_quantity_down' and disable div with the class name 'cart_quantity_input'. Otherwise show it"

with this line of code:

$(document).ready(function() {

var refCodes = $('.cart_ref').text;


if (refCodes = 'MAG04WH30') {
  $('.cart_quantity_up').hide();
  $('.cart_quantity_down').hide();
  $('.cart_quantity_input').prop('disabled','disabled');
}
else{
  $('.cart_quantity_up').show();
  $('.cart_quantity_down').show();
  $('.cart_quantity_input').prop('available','available');
}
});

Could someone tell me what i'm doing wrong?

1

There are 1 answers

1
Ram On

text is a method. You should call it using invocation operator (). Also for comparison you should use the == or === operator.

var refCodes = $('.cart_ref').text();

if (refCodes === 'MAG04WH30') {
   // ...
}