Reputation: 37474
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?
Upvotes: 1
Views: 152
Reputation: 227270
Use .add
dynS.add(cssA).empty().text('#target p:first-of-type {color: red;}');
Upvotes: 1
Reputation: 79830
Try using .add
see below,
dynS.add(cssA).empty().text('#target p:first-of-type {color: red;}');
Upvotes: 3