$('.desktop_search').css({
visibility: 'visible',
width: '100%',
opacity: '1'
});
For instance, I'm changing the element with class desktop_search using JS above. Will it be better to provide all those CSS in my CSS Stylesheet first and just do toggleClass(new_class_name) or is it the same if I did the above? I'm asking because I've changed quite a lot of CSS styles using JS and I'm worried that it might have an impact to my performance. Most of the JS I use is to change CSS when a particular element is clicked or when the page is scrolled, etc.
EDIT:
More details. For example, I'd like an element this_element_will_expand to expand from width: 0 to width: 100% when I click on trigger_a_element which is a. Therefore, I will use this JS:
$('.trigger_a_element').click(function() {
if ($('.this_element_will_expand').css('width') == 0)
$('.this_element_will_expand').css('width', '100%');
else
$('.this_element_will_expand').css('width', '');
});
toggleClass. Use CSS for styling as much as you can. U will be aware of, when you will have to do something with Javascript. Don't worry about the performance, in this case, setting styles with javascript will only affect the performance if you did this like 10x per second, otherwise it is completely OK.a) etc. I'm really just changing the styles from widthxto widthyto mimic animation using JS.