Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  86] [ 1]  / answers: 1 / hits: 30951  / 7 Years ago, fri, february 10, 2017, 12:00:00

I have the following situation:



.my-nice-class {
max-width: 90%;
max-height: 90%;
}


This code lies in the first <style>...</style> in the html page.
I would like to override this global css, by setting for instance new properties values like in the example below:



.my-nice-class {
max-width: 40%;
max-height: 40%;
}


How can I accomplish this with pure Javascript?



Thank you all,



Nano


More From » html

 Answers
90

Modify the css as you want by modifying this object



document.getElementsByTagName(style)[0].innerHTML


OR



Modify style attribute of relevant DOM objects



document.getElementsByClassName(my-nice-class).style[0] = max-width: 40%;max-height: 40%;


NOTE: You have to use a for loop instead of style[0] if you have multiple objects.


[#58990] Wednesday, February 8, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
braydon questions
Tue, Nov 23, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 4 Years ago
Fri, May 15, 20, 00:00, 4 Years ago
Fri, Mar 27, 20, 00:00, 4 Years ago
;