if else statement in jquery

if else statement in jquery

I have found out I could not use an if statement in Jquery (unless done with plain js instead).

Do you think creating two if statements are the best practice to achieve this?

  1. $(document).ready(function() {

  2.         $('#select_preferences').multiselect({
  3.             buttonText: function(options, select) {
  4.                 return 'Look for users that:';
  5.             },
  6.             buttonTitle: function(options, select) {
  7.                 var labels = [];
  8.                 options.each(function() {
  9.                     labels.push($(this).text());
  10.                 });
  11.              if(!labels.length ===0 )
  12.             {
  13.              $('#range-div').removeClass('hide');
  14.             }
  15.             if (labels.length ===0)
  16.              $('#range-div').addClass('hide');
  17.                 return labels.join(' - ');
  18.      
  19.             }
  20.         });