[Solved] turn this jquery into an if/else statement [closed]


Let’s break this into bare parts, and fix the indentation. Then use some static analysis to compact the if statements.

<!--script for changing Number of Columns-->
$(window).load(function(){

  function oneColumnClick() {
    $('.IH_pINameRow').removeClass("floatLeft ");
    $('.IH_pINameRow').addClass("floatNone ");
    $('.odd').removeClass("leftMargin");
    $('.even').removeClass("rightMargin ");
    $('.pI_nameText').removeClass("textAlignLeft textAlignRight");  
    $('.pI_nameText').css('font-size', '2em');
    $('.pI_nameText').addClass("1col");
    $('.pI_nameText').removeClass("2col");
    $('label.twoColumn').css('background-position', '-104px -52px');
    $('label.oneColumn').css('background-position', '-104px -26px');
  }

  function twoColumnClick() {
    $('.IH_pINameRow').removeClass("floatNone ");
    $('.IH_pINameRow').addClass("floatLeft ");
    $('.odd').addClass("leftMargin");
    $('.even').addClass("rightMargin ");
    $('.pI_nameText').css('font-size', '1em');
    $('.pI_nameText').removeClass("1col");
    $('.pI_nameText').addClass("2col");
    $('.odd').removeClass("textAlignLeft");
    $('.even').removeClass("textAlignRight");
    $('.even, .odd').addClass("textAlignCenter");
    $('label.twoColumn').css('background-position', '-104px -26px');
    $('label.oneColumn').css('background-position', '-104px -52px');
    $('label.leftAlignment').css('background-position', '-104px -52px');
    $('label.centerAlignment').css('background-position', '-104px -26px');
  }

  var idx = $('select[name="numNames"]').children('option:selected').index();
  if (idx < 7){
    $('.oneColumn').click(oneColumnClick);
    if (idx > 3){
      $('.twoColumn').click(twoColumnClick);
    }
  }
}); 

17

solved turn this jquery into an if/else statement [closed]