1

Is there any way to remove this duplicate code?

ldbShow.css({
    'left': 'auto',
    'top': 'auto'
})
ldbForum.css({
    'left': 'auto',
    'top': 'auto'
})

I was thinking about something like this:

(ldbForum, ldbShow).css({
    'left': 'auto',
    'top': 'auto'
})

4 Answers 4

1

You can declare a style as an object and reuse it.

var css = { 'left': 'auto', 'top': 'auto' };
ldbShow.css(css);
ldbForum.css(css);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use .add() method

Create a new jQuery object with elements added to the set of matched elements.

ldbForum.add(ldbShow).css({
'left': 'auto',
'top': 'auto'
})

Comments

0

You can use the add() method to join two or more jQuery objects together:

ldbShow.add(ldbForum).css({
    'left': 'auto',
    'top': 'auto'
});

Note that a better solution all together would be to use a common class on all the elements and then select them in a single jQuery object.

Comments

0

use .add() method:

ldbShow.add(ldbForum).css({
    'left': 'auto',
    'top': 'auto'
})

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.