$('.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', '');
});