coffeescript - How to combine js lines into one? -


hi have several js/mootools code in coffee file want combine in

        $$("#head").setstyle('border-right-color','#e64626');         $$("#head").setstyle('background','#e64626');         $$("#console").setstyle('border-right-color','#e64626');         $$("#console").setstyle('background','#e64626'); 

is possible combine 1 line?

although @sergio gave correct answer , wanted, it's wrong thing (though answer not @ fault, question off).

setting element inline styles in javascript effects not practice. has uses in animation/fx not seem case. reason breaks cascading due high specificity , makes more difficult revert, control or change afterwards. makes harder skin , restyle app there's clear lack of separation of concerns, style in code rigid.

you need solve via css

scenario 1: static, non mutable - not due use of id rather classes but:

#head, #console {     border-right-color: #e6426;     background-color: #e6426; } 

scenario 2: dynamic, need differentiate elements on event such click, focus, mouseover - though can solve of these pseudos :focus or :hover, abstract class:

css:

.highlight-red {         border-right-color: #e6426;         background-color: #e6426; } 

javascript:

var els = $$('#head,#console');  // on whatever event...  els.addclass('highlight-red'); // ... later els.removeclass('highlight-red'); 

you thank later or successor or client, whatever. has added benefit next time need change styling or add more rules differentiate, have 1 place go to. can add transitions / animation effects evergreen browsers.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -