1

I'm trying to avoid the following:

var dynS = $('#dyn-style');
var cssA = $('#css-active');

$('#selectors li').click(function(){
    switch($(this).attr('data-id')){
        case 'first-of-type':
            dynS.empty().text('#target p:first-of-type {color: red;}');
            cssA.empty().text('#target p:first-of-type {color: red;}');

Is there any way I could use the cached selector variables and set the text() as the same on both, to avoid this duplication?

2 Answers 2

3

Try using .add see below,

dynS.add(cssA).empty().text('#target p:first-of-type {color: red;}');
Sign up to request clarification or add additional context in comments.

Comments

1

Use .add

dynS.add(cssA).empty().text('#target p:first-of-type {color: red;}');

1 Comment

oops beat u by 3 secs :P +1 for same answer >.<

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.