0

Here is what I am trying to simplify:

rhp_left.find('.first').removeClass("s7").addClass("s4");
rhp_left.find('.second').removeClass("s5").addClass("s3").after(extra);

As you can see the second one has .after(extra)at the end. So, I have the following js function:

function MY_FUNCTION(a, b, c, d)
{
   rhp_left.find(a).removeClass(b).addClass(c)d;??
}

jQuery(document).on('click', function() {
   MY_FUNCTION('.first', "s7", "s4", d)??
   MY_FUNCTION('.second', "s5", "s3", d)??
});

How do I add this .after(extra) as an option??

1 Answer 1

2

Just use a condition

function MY_FUNCTION(a, b, c, d) {
   var elem = rhp_left.find(a).removeClass(b).addClass(c);

   if (d) elem.after(d);
}

jQuery(document).on('click', function() {
   MY_FUNCTION('.first', "s7", "s4");
   MY_FUNCTION('.second', "s5", "s3", extra);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.