This is a more general question regarding a specific problem, but I will give an example of what I mean. There are many things that you can control with CSS that you can also use with Javascript, but is it better to rely on another?
Example: I have four buttons in the navigator that are assigned the "selected" class when the section with which they are associated is in view. So I can either write a CSS instruction for each button (or make Sass for me using mixin)
#home-butt.selected{ background-image: url(images/home-up.png);} #about-butt.selected{ background-image: url(images/about-up.png);} #work-butt.selected{ background-image: url(images/work-up.png);} #contact-butt.selected{ background-image: url(images/contact-up.png);}
Orrr I can write something in javascript to do the same. (* I gave the images a title attribute that matched the name of the image so that it could from there from there).
title = $(this).attr('title'); $(this).find('img').css("background-image", "url(" + 'images/' + (title) + '-up.png' + ")");
So my question is which is better to use? Is this javascript because it is less lines of code? Or is javascript javascript disabled? Or is it a very situational question when there is not always a right or wrong answer?
Opinions and rebuttals are welcome!
source share