In an application I'm working on. The code outside if then isn't working. How should I achieve that target. For example when I try to place first two lines outside if else. It doesn't work.
Also how can I put repetitive code in some variable and call it with if else. For example this one $(this).before(leftArrowHTML);
$('.lessonNavigation ').on('click', 'li', function () {
if ($(this).is('.assess')) {
$('.lessonNavigation li').not('.assess').attr('class', 'dn');
$('.lessonNavigation li.assess').attr('class', 'dn assess');
$(this).attr('class', 'activeLesson assess');
$(this).prev().addClass('expanded left');
$(this).next().addClass('expanded right');
$(this).before(leftArrowHTML);
$(this).after(rightArrowHTML);
} else if ($(this).is('.new')) {
$('.lessonNavigation li').not('.assess').attr('class', 'dn');
$('.lessonNavigation li.assess').attr('class', 'dn assess');
$(this).attr('class', 'activeLesson');
$(this).next().attr('class', 'expanded right brw');
$(this).next().next().attr('class', 'expanded right');
$(this).before(leftArrowHTML);
$(this).after(rightArrowHTML);
$('.arrow.left').attr('class', 'inactiveRightArrow');
}
});