0
How can we get styles applied to element from CSS class?
I can get inline styles of an element using style property in javascript. In a similar way, can I get styles that are applied from CSS class.
3 Respostas
+ 1
Everything you can create via JavaScript has an equivalent CSS syntax. As a side note, the same is true of HTML. The real issue is JavaScript can style a class two different ways via programming, where CSS can only have a single style that doesn't change. Personally, I would do all styles in CSS and use JavaScript to change the class.
For example, have a class for display:none, a second for display:block, and have JavaScript swap the class of the element to show or hide it.
+ 1
If you're wanting to do this just for visualization, you can inspect the elements in your browser (right mouse button + inspect element); otherwise what you're doing may be wrong, because CSS was just designed for separating style from the rest.
If you want to apply different styles for an element depending on a rule, you can write different classes and change them depending on your rules.
0
var get=document.getElementById('some');
get.style.backgroundColor='green';