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.

6th Apr 2018, 12:38 PM
Yallappa Bestha
Yallappa Bestha - avatar
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.
6th Apr 2018, 2:21 PM
John Wells
John Wells - avatar
+ 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.
6th Apr 2018, 6:54 PM
Maicon Mauricio
Maicon Mauricio - avatar
0
var get=document.getElementById('some'); get.style.backgroundColor='green';
6th Apr 2018, 3:51 PM
wenz
wenz - avatar